rstacruz / Ajaxapi
Minimal AJAX library for APIs. Supports promises
Stars: ✭ 18
Programming Languages
javascript
184084 projects - #8 most used programming language
ajaxapi
minimal ajax library.
- optimized for consuming restful api's
- small and compact (< 6kb gzipped)
- uses promises
- supports node.js and the browser
var ajaxapi = require('ajaxapi');
var API = ajaxapi('https://api.github.com');
API.get('/repo/iojs/io.js')
.then(function (data) {
alert("Stars: " + data.stargazers_count);
})
API.put('/user', { name: 'John Constantine' })
.then(function (data) {
alert("User data was saved");
});
Customization
Before hooks
Hooks before its sent
var API = ajaxapi('https://api.github.com');
API.before(function (ctx) {
ctx.headers['X-Access-Token'] = '...';
ctx.headers //=> {}
ctx.method //=> "GET"
ctx.url //=> "https://api.github.com/foo/bar"
ctx.data //=> {}
});
After hooks
Promise stuff -- to be appended to the chain via .then()
after the body is
parsed.
These hooks will be chaining each other.
var API = ajaxapi('https://api.github.com');
API.after(function (data) {
// do stuff
API.response.headers
API.response.statusCode
return data;
});
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].