https://github.com/fluse/client-api
https://github.com/fluse/client-api
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fluse/client-api
- Owner: fluse
- Created: 2016-01-20T15:22:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-19T14:26:02.000Z (over 8 years ago)
- Last Synced: 2025-02-06T01:02:24.245Z (4 months ago)
- Language: JavaScript
- Size: 108 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Client API
[](https://www.paypal.me/schauf)
Rest like client api calls
## Install
```shell
> npm install client-api --save
```dependencies:
- [superagend](https://github.com/visionmedia/superagent)
- [node-extend](https://github.com/justmoon/node-extend)## Use
```javascript
var Api = require('client-api');
```## Create
```javascript
var api = new Api(settings);
```## Settings
```javascript
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
```javascript
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
```javascript
api('get', '/category/article', {}, callback);
```### GET with Params
each :{name} will replace by key value from params object
```javascript
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
```javascriptvar data = {
name: 'newName'
};api('put', 'category/article/:id', {
id: inputId
}, data, callback);
```### DELETE
```javascriptapi('delete', 'category/article/:id', {
id: inputId
}, callback);
```