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

http2-request

v1.0.2

Published

smol package to work with http2 requests

Downloads

22

Readme

http2-request

npm version build status downloads js-standard-style

Super smol HTTP/2 request library :package:. Optimized for JSON APIs.

Usage

var request = require('http2-request')
var fs = require('fs')

var opts = {
  url: 'https://localhost:8001',
  connectOpts: {
    ca: fs.readFileSync('~/http2-request/cert.pem')
  },
  clientOpts: {},
  headers: {
    ':path': '/'
  }
}

request(opts, function (err, headers, body) {
  if (err) throw err
  if (!headers.isOk()) throw new Error(`statusCode is ${headers.statusCode}`)
  console.log('headers', headers)
  console.log('body', body)
})

API

request(opts, cb)

Create a new instance of http2-request. Takes a few options to connect to an HTTP/2 client and create and HTTP/2 session:

  • opts.headers: headers object to pass in the request.
  • opts.json: Boolean, defaults to true. Returns either a JSON object or a string when false.
  • opts.url: A URL to send a request to. http2-request will create a new URL object to get the origin
  • opts.clientOpts: HTTP/2 session request opts. When none are passed, will use defaults.
  • opts.connectOpts: HTTP/2 connect options. When none are passed, will use defaults. If you're developing locally, pass in { rejectUnauthorized: false } to avoid rejections from the server, otherwise pass in a cert under the ca flag.

response

Request has a signature of (err, headers, body):

  • err: err from either a connection or a request.
  • headers: HTTP/2 errors object returned from the response.
  • body: Response body. Will return a string if opts.json is false, otherwise a JSON object.

headers.isOK()

A convenience method to see if the response comes back <=299 for easier error checking. Returns a boolean.

headers.statusCode

A convenience method from HTTP/1.1 to read off the status code. You can also do so by headers[:status].

Install

npm install http2-request

License

Apache-2.0