smol package to work with http2 requests
Last updated 3 years ago by lrlna .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install http2-request 
SYNC missed versions from official npm registry.


npm version build status downloads js-standard-style

Super smol HTTP/2 request :package:.


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

var opts = {
  url: 'https://localhost:8001',
  connectOpts: {
    ca: fs.readFileSync('~/http2-request/cert.pem')
  json: true,
  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)


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.


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.


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


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


npm install http2-request



Current Tags

  • 1.0.1                                ...           latest (3 years ago)

2 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (4)
Dev Dependencies (2)
Dependents (0)

Copyright 2014 - 2016 © |