client-api

0.1.12 • Public • Published

Client API

Donate

Rest like client api calls

Install

> npm install client-api --save

dependencies:

Use

var Api = require('client-api');

Create

var api = new Api(settings);

Settings

var settings = {
    token: '32digits',
    version: 'v1',
    baseName: '/api/',
    dataType: 'json'
}
name type description
token String server authorization with token
version String api version
baseName String base url without domain.tld
dataType String data format

Calls

api(method, path, params, data, callback);
name type description
method String get, post, put, delete, path
path String api version
params Object set maximal video amount
data Object option on get and delete
callback Function recieving function

GET

api('get', '/category/article', {}, callback);

GET with Params

each :{name} will replace by key value from params object

var params = {
    publisher: 'times',
    category: 'book',
    id: 5
};
 
api('get', '/:publisher/:category/:id', params, callback);

Result http://domain.tld./api/v1/times/book/5

PUT / POST

 
var data = {
    name: 'newName'
};
 
api('put', 'category/article/:id', {
    id: inputId
}, data, callback);

DELETE

 
api('delete', 'category/article/:id', {
    id: inputId
}, callback);

Package Sidebar

Install

npm i client-api

Weekly Downloads

0

Version

0.1.12

License

MIT

Last publish

Collaborators

  • fluse