apist
Simple REST API client
THIS PACKAGE IS NO LONGER MAINTAINED
Install
$ npm install --save apist
Usage
import Apist from 'apist';
const users = new Apist('users');
users.fetch(10, { query: 'query' }).then(data => console.log(data.firstName));
Within the used fetch
. You can add polyfill to your project.
Configure to work with your API, by overriding methods.
class CustomApist extends Apist {
constructor(resource) {
super(resource);
this.contentType = 'application/json';
this.options = {};
this.headers = {};
this.host = 'http://example.com';
this.namespace = 'api/v2';
}
handleError(err) {}
serialize(data) {}
deserialize(req, res) {}
}
API
Apist(resource)
resource
Type: string
The name of the API resource.
Instance
All CRUD methods return a Promise
.
.fetchAll([query])
GET /resource?query
query
Type: object
.fetch(id, [query])
GET /resource/:id?query
id
Type: number|string
query
Type: object
.create(data)
POST /resource
data
Type: any
.update(id, data)
PUT /resource/:id
id
Type: number|string
data
Type: any
.delete(id)
DELETE /resource/:id
id
Type: any
Related
License
MIT © Timofey Dergachev