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

thip

v0.2.0

Published

Ultra-Thin, Dependency-Free, Promise-Based HTTP request client.

Downloads

1

Readme

thip

Build Status

Ultra-Thin, Dependency-Free, Promise-Based HTTP request client.

Features

  • Ultra thin, and lightweight
  • Dependency free
  • Promise based
  • Only supports Node.js (>= 6), not supports browser
  • Supports HTTPS
  • Follows redirect by default

Install

npm install thip

Usage

thip(options[, data])

  • options <object>|<string> - Any options not included below will be passed to http.request(options).
    • url <string> - If you specified this option, parse the url and merged to other options.
    • followRedirect <boolean> - Follow HTTP 3xx responses as redirects. Defaults to true.
    • maxRedirects <number> - The maximum number of redirects to follow. Defaults to 10.
  • data <string>|<buffer> - This will be passed to request.write(chunk).

This function returns Promise object which resolves response object. The response object is an instance of http.IncomingMessage, but contains body property.

const thip = require('thip');

thip('http://example.com/').then((res) => {
  console.log(res.body);
});
const thip = require('thip');
const querystring = require('querystring');

const data = querystring.stringify({
  'msg': 'Hello World!',
});

const options = {
  method: 'POST',
  url: 'http://example.com/message',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(data),
  },
};

thip(options, data).then((res) => {
  console.log('Post successful!');
});

thip.get(options[, data])

  • options.method assigns "GET" by default.
  • If data is <object>, the data is encoded as URL query.
thip.get('http://example.com/', { foo: 'bar' });

This is same as below.

thip('http://example.com/?foo=bar');

thip.post(options[, data])

  • options.method assigns "POST" by default.
  • If data is <object>, the data is encoded as x-www-form-urlencoded.
const thip = require('thip');

thip.post('http://example.com/', { foo: 'bar' });

This is same as below.

const thip = require('thip');
const querystring = require('querystring');

const data = querystring.stringify({
  'foo': 'bar',
});

const options = {
  method: 'POST',
  url: 'http://example.com/',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(data),
  },
};

thip(options, data);

Error Handling

If HTTP response status code is 4xx or 5xx, the promise is rejected with HttpClientError or HttpServerError.

thip('http://example.com/not_found_path').catch((error, res) => {
  console.log(error.name); // "HttpClientError"
  console.log(res.statusCode); // 404
})