resource-agent
Node module to create simple API clients for endpoints that expose a common REST-like interface.
Install
$ npm install resource-agent
Usage
Create a "user" resource and do some basic http "CRUD" operations.
var resource = ; // create a new "users" instance var users = ; // GET /users usersall{ if err throw err; console;}; // GET /users?tag=awesome usersall tag: 'whatever' { if err throw err; console;}; // GET /users/123456789 users; // POST /users users; // PUT /users/123456789 users; // DELETE /users/123456789 users;
Custom Methods
Now not all methods that are provided implicity will get you what you need. For that, you can pass an additional parameter to the constructor to "decorate" the resource prototype.
var users = ; // GET /users?tagged=awesome users;
Options
You can set global options on the constructor it self. However, not that it will populate the value to all instances. Otherwise, just pass it into the constructor.
var resource = ; resourcehost = 'http://localhost:3000'; resourceheaders = secret: 'top-secret-header';
TODO
- tests
- response parsing
License
MIT