API Service
Simple http service / api wrapper for client-side JavaScript or Node.js. This class helps you creating collections of api-resources with an intuitive and simple api.
Setup
npm install api-service
Simple usage
var Service = ; var myApiWrapper = 'http://localhost/api' // Add users endpoints // Add posts endpoints // Add a middleware function that sets authorization header to request ; // GET /usersmyApiWrapperusers; // GET /users?q=foomyApiWrapperusers; // POST /posts with payloadmyApiWrapperposts; // DELETE /posts/some_idmyApiWrapperposts;
Service
This class is used to group and organise instances of the api-resource class.
Service instances are also event-emitters and they will propagate all events sent by any of their Resource
children.
Constructor
baseUrl
(String) Service base URL (E.g.'http://www.my-api.com'
) - without/
at the end
Events
The events propagated by this class are documented in the Resource readme.
Methods
.add(namespace, [ options ])
Add an endpoint to the service. This will be an instance of Resource pass the options to its constructor.use(middleware)
Add a middleware function to the resource. The function will be called on theResource
instance and receive as arguments theXMLHttpRequest
request instance and thenext
function to proceed.
Test
Tests are currently written on server-side only. Run npm install
and npm test
to test.
Contribution
Contributions are welcome as long as documented and tested.
License
Copyright (c) 2014 Kano Computing Ltd. - Released under the MIT license