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

requisition

v1.7.0

Published

ES7 async/await ready http client

Downloads

5,898

Readme

requisition

NPM version Build status Test coverage Dependency Status License Downloads

A light, fluent node.js HTTP client for ES6. Heavily inspired by superagent as well as fetch. Designed with ES7 async/await in mind.

The API is quite minimal for now. Features will be added while people request or use them.

var req = require('requisition');

// GET a JSON body
async function () {
  var res = await req('/users.json');
  var body = await res.json();
}

// POST an image file
async function () {
  var res = await req.post('/images.json').sendFile('image.png');
  var body = await res.json();
}

Differences

This is similar to other AJAX libraries like axios except:

  • Does not have browser support
  • Does not depend on gigantic options objects
  • Many utilities for handling HTTP responses like saving to a file

API

var request = require('requisition');

Request

request(url)

GET a url, return the response object.

request[VERB](url)

VERB a url, specifically when it's not GET.

request().then( response => )

Send the request and wait for the response.

request('/').then(function (response) {

})

request().set(headers)

Set an object of headers.

request().set(header, value)

Set a single header.

request().auth(name, pass)

Add basic authorization.

request().agent(agent)

Set http agent.

request().timeout(ms)

Set timeout.

request().redirects(num)

Set max redirect times.

request().ifModifiedSince(date)

Set header If-Modified-Since.

request().ifNoneMatch(value)

Set header If-None-Match.

request().type(type)

Set header Content-Type.

request().cookie(key, value, options)

Set cookie, uses cookie.serialize()

request('/cookie')
  .cookie(name, value, options)
  .then(function (response) {
    console.info(response.cookies);
  })

request().query(params)

Add query string.

request().send(data)

Add http body.

request().sendFile(filename)

Send file.

Response

response.status

The status code of the response.

response.headers

The header object of the response.

response.is(types...)

Infer the Content-Type of the response, similar to Koa or Express' method. See type-is.

response.get(header)

Get the value for a header.

response.charset

Get charset.

response.etag

Get header ETag.

response.lastModified

Get header Last-Modified.

response.cookies

Get cookies

request('/cookie').then(function (response) {
  console.info(response.cookies);
})

#### response.buffer().then( buffer => )

Return a single `Buffer` for the entire response.

#### response.text().then( text => )

Return a single `String` for the entire response.

#### response.json().then( body => )

Automatically parse the JSON of the response.

```js
request('/users.json').then(function (response) {
  assert(response.status === 200, 'Bad response!');
  assert(response.is('json'), 'Bad type!');
  return response.json()
}).then(function (body) {
  console.log(body);
})

response.saveTo([filename]).then( filename => )

Save the response to a file. If no filename is specified, saves to a random file in your temporary directory.

request('/file.txt').then(function (response) {
  return response.saveTo('/tmp/file.txt');
}).then(function () {
  console.log('file saved!');
})

response.dump()

Dumps the response. Execute this if you haven't handled the body.

response.destroy()

Destroy the response.