0.3.14 • Published 9 years ago
simplehttpservice v0.3.14
Promisify backend API to frontend
Usage
import Service from 'simplehttpservice';
// define your API map
var APIS = [
{ name: 'blog', url: '/blogs/:id' },
{
name: 'comment',
url: '/comments'
}
];
var config = {
headers: {
'Content-type': 'application/json'
},
withCredentials: true
};
var service = new Service(config);
service.config(APIS);
export default service;
import API from './service';
API.blog.post({ name: 'hello world' })
.then(handleResolve, handleReject);
API
import Service from 'simplehttpservice';
/**
* config {Object} custom config properties for all ajax requests
*
*/
new Service(config);
Installation
$ npm install simplehttpservice --save
Difference with fetch
Rules
// rule is a function you can get response and decide resolve/reject before Application code
function rule(xhr, resolve, reject) {
if (!xhr.headers['X-header']) return reject('no specify header');
resolve();
}
var service = new Service({ rules: [ rule ] });
Formatter
// formatter can help you format response to Application code
// For instance, you backend API is: { data: { id, name } }
// let's format it to { id, name }
function formatter(raw) {
var data = JSON.parse(raw);
return JSON.stringify(raw.data);
}
var service = new Service({ formatter: formatter });
License
MIT
0.3.14
9 years ago
0.3.13
9 years ago
0.3.12
9 years ago
0.3.11
9 years ago
0.3.10
9 years ago
0.3.91
9 years ago
0.3.9
9 years ago
0.3.8
9 years ago
0.3.7
9 years ago
0.3.6
9 years ago
0.3.5
9 years ago
0.3.4
9 years ago
0.3.3
9 years ago
0.3.2
9 years ago
0.3.1
9 years ago
0.2.7
9 years ago
0.2.6
9 years ago
0.2.5
9 years ago
0.2.4
9 years ago
0.2.3
9 years ago
0.2.2
9 years ago
0.2.1
9 years ago
0.2.0
9 years ago
0.1.3
9 years ago
0.1.2
9 years ago
0.1.1
9 years ago
0.1.0
9 years ago
0.0.25
9 years ago
0.0.23
10 years ago
0.0.21
10 years ago
0.0.20
10 years ago
0.0.19
10 years ago
0.0.18
10 years ago
0.0.17
10 years ago
0.0.16
10 years ago
0.0.13
10 years ago
0.0.12
10 years ago
0.0.1
10 years ago