Socket
Socket
Sign inDemoInstall

ajaxapi

Package Overview
Dependencies
19
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ajaxapi

minimal ajax library.


Version published
Weekly downloads
5
increased by150%
Maintainers
1
Install size
508 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 03 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc