ajaxapi
minimal ajax library.
Last updated 6 years ago by rstacruz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ajaxapi 
SYNC missed versions from official npm registry.

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;
});

Current Tags

  • 0.0.0-pre5                                ...           latest (6 years ago)

3 Versions

  • 0.0.0-pre5                                ...           6 years ago
  • 0.0.0-pre4                                ...           6 years ago
  • 0.0.0-pre3                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (2)
Dev Dependencies (5)
Dependents (3)

Copyright 2014 - 2016 © taobao.org |