0.3.14 • Published 8 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
8 years ago
0.3.13
8 years ago
0.3.12
8 years ago
0.3.11
8 years ago
0.3.10
8 years ago
0.3.91
8 years ago
0.3.9
8 years ago
0.3.8
8 years ago
0.3.7
8 years ago
0.3.6
8 years ago
0.3.5
8 years ago
0.3.4
8 years ago
0.3.3
8 years ago
0.3.2
8 years ago
0.3.1
8 years ago
0.2.7
8 years ago
0.2.6
8 years ago
0.2.5
8 years ago
0.2.4
8 years ago
0.2.3
8 years ago
0.2.2
8 years ago
0.2.1
8 years ago
0.2.0
8 years ago
0.1.3
8 years ago
0.1.2
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago
0.0.25
8 years ago
0.0.23
8 years ago
0.0.21
8 years ago
0.0.20
8 years ago
0.0.19
8 years ago
0.0.18
8 years ago
0.0.17
8 years ago
0.0.16
8 years ago
0.0.13
9 years ago
0.0.12
9 years ago
0.0.1
9 years ago