npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

armrest

v5.0.2

Published

A high-level HTTP / REST client for Node

Downloads

91

Readme

Armrest

Build Status

A high-level HTTP / REST services client for Node.

Table of Contents

Install

Install with npm:

$ npm install armrest

Usage

Example

Set up a client and issue a GET request:

var armrest = require('armrest');
var github = armrest.client('https://api.github.com');

github.get({
	url: '/orgs/:organization',
	params: { organization: 'shutterstock' },
	success: function(organization) {
		// do something
	}
});

Instantiating a REST Client

The armrest.client() factory takes two forms: send the base URL as a string if that will get you going, or send an object with parameters below for more flexibility.

base

The base URL, including any or all of the scheme, hostname, port, and path. This option overrides scheme, hostname and port.

protocol

The scheme part of the base URL if base is not specified, either http or https. Defaults to http. Aliased as scheme as well for compatibility.

host

The host part of the base URL (hostname:port) if base is not specified.

hostname

The hostname part of the base URL if base is not specified.

port

The port part of the base URL if base is not specified.

timeout

Number of milliseconds to wait first for establishing the socket connection and sending the request, and then again for receiving the response.

serializer

Optional parameter, an object specifying a contentType, and functions to serialize and deserialize request and response bodies.

logger

Instance of some logger that implements debug(), info(), warn(), and error().

logLevel

String indicating criticality of messages to log; one of debug, info, warn, or error.

Methods

get(), post(), put(), patch(), delete(), head()

Make an HTTP request to the service, given the parameters below.

url

The path component of the URL. URLs may have sinatra-style interpolation tokens to be filled in by values from params.

params

Paramaters to be sent with the request. For HEAD, GET and DELETE requests these will be sent as query string parameters. For other HTTP methods, parameters will be serialized according to the serialization scheme associated with the client, and sent in the body of the request.

success

Callback to be executed upon success, with the deserialized response as the first parameter, followed by the full response object.

error

Callback to be executed upon failure, with the error as the first parameter, followed by the full response object.

complete

Callback to be executed upon completion, whether the request failed or succeeded, with the error as the first parameter, followed by the full response object, and finally the deserialized response.

Additional parameters are passed through to request.

Working with Many Backend Services

When you're working with a number of services at once, use the following alternate interface to configure clients and get easy access for later use.

configure(name, options)

A class method to register backend services. Send a name for the service, and options expected by the constructor, as detailed above.

var armrest = require('armrest');

armrest.configure('github', {
	base: 'http://api.github.com',
	timeout: 5000
});

armrest.configure('metacpan', {
	base: 'http://api.metacpan.org',
	timeout: 5000
});

Later from elsewhere, load in the module and interact with services by name.

var armrest = require('armrest');

armrest.github.get(...);
armrest.metacpan.get(...);

Working with Many Client Instances

When you're working with a number of client instances and you want them to have the same default behavior, use the following method.

setDefaults(options)

var armrest = require('armrest');

armrest.setDefaults({
	timeout: 10000
});

This will set the default timeout for any request to 10000 milliseconds. To clear the default behaviors, use:

armrest.clearDefaults();

Authors

This library was developed by David Chester and Zubin Tiku at Shutterstock

Contribute

Please do! Check out our contributing guide.

License

MIT © 2012-2017 Shutterstock Images, LLC