Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including simple-api-client with all npm packages installed. Try it out:

var simpleApiClient = require("simple-api-client")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

simple-api-client v0.6.2

quickly create a simple and extendable api-client

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free