An opinionated client for RESTful APIs (particularly OpenStack's).
This project aims to provide a very opinionated core client which can be used in either node.js or in the browser (browser support not yet complete) to communicate with a RESTful APIs, including but not limited to any OpenStack-compatible API.
The aims of this project are very specific:
Require absolutely minimum boilerplate code for adding new API resource managers.
Provide an extremely stable, backwards-compatible, carefully maintained API to users of this library. Changes in remote APIs should be managed under-the-hood when necessary.
Do not support every legacy authentication mechanism or every legacy vagary of remote APIs. (The included OpenStack components are intended for use on Essex or newer OpenStack deployments running Keystone authentication.)
Do not mirror the APIs precisely. Instead provide a clean interface which is
consistent across every API resource and raise
when a method is not supported by the underlying API.
Where possible, hacks should be added on specific managers to emulate
methods are not natively supported by the API. For example,
be emulated by making multiple calls, etc.
Any client extending this library should do the utmost to avoid breaking the fundamental API contract that this library provides.
The following shows off a variety of the features of the client:
var Keystone = require"openclient"getAPI'openstack' 'identity' '2.0';var client =url: <auth url>debug: trueclientauthenticateusername: <username>password: <password>project: <project name>// Callbacks can either be success/error handlers in the options object or// a callback function as the last argument.clientprojectsallendpoint_type: "adminURL" // Defaults to "publicURL".// Callbacks receive the result of the call;var updated_project project = projects0;clientprojectsupdateendpoint_type: "adminURL"id: projectiddata:name: <>updated_projectname === <>; // trueconsole.errorerr;;console.errorerr;;;
Plenty more examples are available in the integration tests for the clients themselves.
The primary methods that the base
Manager class exposes are:
all: retrieve a list of all available resources.
get: retrieve a single resource.
create: create a new resource.
update: update an existing resource.
del: delete an existing resource.
in_bulk: retrieve each of the resources in a given list of ids.
filter: retrieve a list of resources which match the filter criteria. (not yet implemented in most cases)
The tests for the clients are entirely integration tests. They require a functioning OpenStack deployment, and are best-tested against a clean DevStack deployment.
To run the tests for a given client, use the test runner with your OpenStack
credentials (using a fresh DevStack installation is recommended); you may set
OS_ variables in the environment, or you can pass the required
arguments like so:
node <client dir>/tests/run.js--url=http://<keystone url>:5000/v2.0--username=<admin username>--project=<admin project>--password=<admin password>
This library is published under a BSD license and may be freely used in accordance with those terms.