Skip to content
Tim Cameron Ryan edited this page Nov 27, 2013 · 38 revisions

Rem is an extensible HTTP client with middleware for Node.js and browsers. Built to power anything REST client, Rem comes with support for popular web services out of the box.

Topics

Overview

Rem has simple and flexible syntax for making HTTP requests:

var rem = require('rem');

rem.json('http://graph.facebook.com/timcameronryan').headers({
  'X-Custom-Header': '1'
}).get(function (err, content, res) {
  if (err) {
    console.error(err);
  } else {
    console.log('Returned this JSON:', content);
  }
})

In addition to json, Rem supports returning content as a stream, buffer, text, form data, and xml (with libxmljs).

Rem lets you write your own API clients by configuring hostnames, default content-types, headers, and even OAuth setup. For example, a simple Tumblr library:

var tumblr = rem.createClient({
  "base": "http://api.tumblr.com/v2",
  "configParams": {"api_key": "key"},
  "uploadFormat": "form"
}).configure({
  "key": process.env.TUMBLR_KEY
});

// Get info about the "staff" blog
tumblr('blog', 'staff.tumblr.com', 'info').get(function (err, json) {
   console.log('Response', json);
});

Rem can authenticate users using OAuth. These tokens can be saved and restored if you want to run a bot or service.

Rem comes with support for a number of APIs built-in, which you can access with the rem.connect(...) method.

var fb = rem.connect('facebook.com').configure({
  'key': process.env.FB_KEY
  'secret': process.env.FB_SECRET
});

fb('timcameronryan').get(function (err, json) {
  console.log('Tim\'s profile:', json);
});

Scripting

Instead of specifying credentials yourself with .configure(), Rem can cache your API key/secret credentials using .promptConfiguration, and authenticate a user's account using .promptAuthorization.

You can do both at once with .prompt, letting you easily write API-consuming scripts from your command line. Because all the configuration is prompted by Rem, it's simple to share these scripts online:

var rem = require('rem');
rem.connect('github.com').prompt(function (err, user) {
  user('notifications').get(function (err, notifications) {
    console.log('Github notifications:', notifications);
  });
});