0.1.13 • Published 9 years ago
restfulapi-sdk v0.1.13
restfulapi-sdk
standard restful api sdk with cache and promise.
What achieved
- standard restful api sdk for
get
,post
,put
,delete
,patch
andoptions
methods. - save data in browser side, use
cache
method. - promise callback.
usage
$ npm install restfulapi-sdk
$ bower install restfulapi-sdk // or use bower
Include sdk.js
in /dist
by tag , you can also require js by require('restfulapi-sdk')
var urls = {
order: '/api/order/:id',
user: {
password: '/api/user/:id/password'
}
};
var config = {
urlPrefix: 'api/', // you can add a urlPrefix, default ''
cache: false, // open cache, default false (only valid with get method)
cachePrefix: 'api', // cache prefix, default 'api'
overdue: 3600, // cache time, unit second, default 3600
overdueDay: null, // cache days number,prior to overdue,default null
isSession: false // use sessionStorage for cache or not
};
const APISDK = require('restfulapi-sdk');
const API = new APISDK(urls, config);
var todo1 = API.order.get({
id: id,
otherRouteParams: ...
});
var todo2 = API.order.post({
id: id,
otherRouteParams: ...
});
// cache data with get method, will get remote data first
API.order.cache({
id: id,
otherRouteParams: ...
}).then((res, httpCode, refer) => {
// success
// do something
refer(true, ...newRes); // arguments in next success()
refer(false, ...newErr); // arguments in next error()
}, (err, httpCode) => {
// no data or overdue
});
APISDK.all([todo1, todo2])
.then((successArr, errorArr, refer) => { // only trigger in success function
// successArr[0] = [indexinPromiseArr, ...returnParams]
});
API.user.put({
id: id
}, {
newPassword: newPassword
}).then(() => {}, () => {}); // while use api data
/* static method for httpCode */
APISDK.httpCode((code) => {
console.log(code);
});
/* static method for remove Cache */
APISDK.remove(key, isSession); // cache key, and use sessionStorage for cache or not
develop
$ clone restfulapi-sdk && make dev // then view http://localhost:8888
0.1.13
9 years ago
0.1.12
9 years ago
0.1.11
9 years ago
0.1.10
9 years ago
0.1.9
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago
0.0.16
10 years ago
0.0.15
10 years ago
0.0.14
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.11
10 years ago
0.0.10
10 years ago
0.0.9
10 years ago
0.0.8
10 years ago
0.0.7
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
10 years ago
0.0.1
10 years ago