npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

simple-api-client

0.6.2 • Public • Published

simple-api-client Build Status

create a quick simple extendable api client

Usage

Initialize

Require a Class

var ApiClient = require('simple-api-client');
var facebook = new ApiClient('http://graph.facebook.com');

Or just Require an Instance

var facebook = require('simple-api-client')('http://graph.facebook.com');

Http methods (post, get, put, patch, post, del, ...) (uses methods);

var facebook = require('simple-api-client')('http://graph.facebook.com'); // you can require the Class or instance directly.
 
facebook.get('photos', function (err, res, body) {
  // ...
});

Uses request under the hood

Works in the browser too, using browser-request under the hood

var facebook = require('simple-api-client')('http://graph.facebook.com'); // you can require the Class or instance directly.
 
var opts = {
  /* request options! */
  json: true,
 
  /* adds option for path */
  path: 'photos'
}
 
facebook.get(opts, function (err, res, body) {
  // ...
});
 
// or
 
facebook.get('photos', opts, function (err, res, body) {
  // ...
});
 
// accepts paths as arrays or multiple strings
 
facebook.get('photos', photoId, function (err, res, body) {
  // ...
});
 
facebook.get(['photos', photoId], function (err, res, body) {
  // ...
});
 

Great Base Class for Creating an ApiClient

var util = require('util');
var ApiClient = require('simple-api-client');
 
var Facebook = function (/* ... */) {
  /// ...
}
 
util.inherits(Facebook, ApiClient);
 
Facebook.prototype.getPhotos = function (cb) {
  this.get('photos', cb);
}

License

MIT

install

npm i simple-api-client

Downloadsweekly downloads

9

version

0.6.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability