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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sails-hook-restful-promise

v1.1.2

Published

Sails JS hook to communicate with RESTful APIs (HTTP/HTTPS) and return a Promise without a single external dependency

Readme

sails-hook-restful-promise

Sails JS hook to communicate with RESTful APIs (HTTP/HTTPS) and returns a Promise.

All this without even a single external dependency

Installation

npm install --save sails-hook-restful-promise

Usage

sails.hooks.RESTful
            .send(options)
            .then(function (response) {
                console.log(response);
            })
            .catch(function (err) {
                console.error(err);
            });

Where options is an Object, which can have the following keys (all optional):

  • protocol: (String) http or https (Default is http)
  • hostname: (String) The API endpoint (Default is localhost)
  • port: (Number) The API port (Default is 80 for http and 443 for https)
  • path: (String) The API Path (Default is empty path)
  • body: (String) The API request body (if any) (Default is empty body)
  • qs: (Object) The Query String in key value notation. e.g.: {q:'foo',s='bar'} means ?q=foo&s=bar
  • method: (String) The HTTP Method (Defaults to GET)
  • headers: (Object) Any custom HTTP Headers to send in key value notation. e.g.: {'Content-Type': 'application/json'}
  • timeout: (Number) The HTTP API call timeout in milliseconds (Defaults to 0, which means no timeout)
  • returnHeaders: (Boolean) Weather to return HTTP Headers as received from the API Response. Default is false

Response format

If the API call is successful (no matter what the HTTP Status or the response is), the promise resolves with the response object in the following format:

{
    status: 200,
    body: 'The exact body returned by the API Response in String format'
    headers: {
        //Key: 'Value' pairs of all headers retirned by the server.
    }
}

Note: headers is only available when returnHeaders is set to true in request.options.

Defining Defaults

Following options can be defined as defaults from the sails.config. Just add a config/restful.js file in your sails installation with following content:

module.exports.RESTful = {
    protocol: 'http', // Only 'http' or 'https' allowed here
    hostname: 'localhost',
    portHTTP: 80,
    portHTTPS: 443,
    headers: {}, //Any custom HTTP Headers to send in key value notation. e.g.: {'Content-Type': 'application/json'}
    timeout: 0, //If positive, in milliseconds. 0 means don't set timeout
    returnHeaders: false //Weather to return HTTP Headers as received from the API Response
}