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

shh-node-http

v3.1.2

Published

A simple Promise wrapper around the Node.JS http(s) ClientRequest

Downloads

12

Readme

shh-node-http

A simple promise wrapper around Node.JS http(s) ClientRequest

https://nodei.co/npm/shh-node-http.png?downloads=true&downloadRank=true&stars=true

Node version

Simple to use

shh-node-http is designed to be the simplest way to make http calls from your Node application. For convenience it defaults to a Content-Type of JSON and follows redirects.

It supports:

  • http
  • https
  • parsing JSON
  • parsing form
  • passthrough of all other body type

Minimal

shh-node-http has 0 (zero) dependencies, is under 250 LOC including comments / whitespace, and completely exposes the native Node request / response objects so nothing is hidden from you.

Compatibility

shh-node-http has full typings and works with TypeScript, esmodule import, and the old Node module require.

Usage

const { shh } = require('shh-node-http');

shh.post(url: string, body: any, options?: Object)
  .then(response => doSomething(response))
  .catch(e => handleError(e));

Options

  • params - { key: value } query parameters (default null)
  • headers - { key: value } http headers (automatically applies Content-Type, Content-Length)
  • json - true|false encodes and parses the request body as JSON (default true)
  • form - true|false form encodes and parses the request body (default false)
  • timeout - number request timeout in milliseconds, the request will be canceled and the Promise will be rejected once this value is reached (default 30000 - 30 seconds)
  • follow_redirects - true|false whether to follow http redirects (default true)

Examples

plain html get:

const { shh } = require('shh-node-http');

shh
  .get('https://www.google.com/', { json: false })
  .then(response => {
    console.log('status: ', response.statusCode);
    console.log('message: ', response.statusMessage);
  })
  .catch(e => console.error('request failed with error: ', e));

passing query parameetrs

const { shh } = require('shh-node-http');

shh
  .get('https://my-cool-rest-api.com/api/v1/users', { params: { name: 'Bob' } })
  .then(response => {
    console.log('status: ', response.statusCode);
    console.log('message: ', response.statusMessage);
  })
  .catch(e => console.error('request failed with error: ', e));

REST API post

const { shh } = require('shh-node-http');
shh
  .post('https://my-cool-rest-api.com/api/v1/users', {
    name: 'Josh',
    email: '[email protected]',
    password: 'hunter2'
  })
  .then(response => {
    console.log('Created user ', response.body.name);
    hanldeNewUser(response.body);
  })
  .catch(e => {
    console.error('Create user failed woth error: ', e.message);
    handleNewUserError(e.body || e);
  });

using the raw request wrapper:

const { shh, utils } = require('shh-node-http');

shh
  .request('GET', 'https://www.google.com/', null, { json: false })
  .then(response => utils.assertStatus(response))
  .then(response => {
    console.log('status: ', response.statusCode);
    console.log('message: ', response.statusMessage);
  })
  .catch(e => console.error('request failed with error: ', e));