0.0.15 • Published 9 years ago
isofetcher v0.0.15
isofetcher
Fetch-based REST API requests for the browser and Node.js.
Use Anywhere
This library works in the client and on the server.
Install
bower install isofetcher
Note: This requires, at a minimum, resturlify. Older browsers require es6-promises.
Or
npm install isofetcher
Examples
Constructor
var fetcher = require('isofetcher')({resources: ['foo','bar'], fqBaseUrl: 'https://www.web.com/api'});
or
var fetcher = isofetcher({resources: ['foo','bar'], fqBaseUrl: 'https://www.web.com/api'});
Basic Usage
GET
fetcher.foo.get();
Generates GET https://www.web.com/api/foo
Query Parameters
fetcher.bar.get({query: {id: 1}});
Generates GET https://www.web.com/api/bar?id=1
Custom Methods
fetcher.bar.get({customMethod: 'children');
Generates GET https://www.web.com/api/bar/children
fetcher.foo.get({customMethod: 'children', id: 1);
Generates GET https://www.web.com/api/foo/1/children
PUT
fetcher.foo.put({id: 1});
Generates PUT https://www.web.com/api/foo/1
POST
fetcher.bar.post({body: {payload: 1});
Generates POST https://www.web.com/api/bar
PATCH
fetcher.foo.get({id: 1});
Generates PATCH https://www.web.com/api/foo/1
DELETE
fetcher.foo.get({id: 1});
Generates DELETE https://www.web.com/api/foo/1
Headers
fetcher.foo.post({headers: {
'Content-Type' : 'application/json'
});
Cookies
Cookies are not sent by default. Send the credential option to send cookies.
fetch.foo.get({credentials: 'same-origin'});