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

reqi

v1.0.4

Published

Promisified request library with built in functionality for retries, redirects, and body parsing.

Downloads

5

Readme

License: MIT JavaScript Style Guide: Standard Build Status

Reqi

Reqi is a Promisified request library with built in functionality for retries, redirects, and body parsing.

Installation

npm install reqi

Usage

Using Reqi is like using your favorite request libraries, but with promises. Require reqi, instantiate a client, and fire away!

const client = new (require('reqi'))({ json: true })
let data = await client.get('https://example.com/posts')

Reqi also includes convience methods for quick requests, such as get and put.

;(async function (postNum = 1) {
  // create a new reqi client with json parsing
  const jsonClient = new (require('reqi'))({ json: true })

  try {
    // grab a post
    let { body } = await jsonClient.get(
      `https://jsonplaceholder.typicode.com/posts/${postNum}`
    )

    // soup up the original post a bit
    let shnazzyTitle = body.title.toUpperCase() + '!!!'
    let excitingContent = body.body.replace('.', '!')

    const recycledPost = {
      userId: 1,
      id: 1,
      title: shnazzyTitle,
      body: excitingContent
    }

    // publish our new post
    let res = await jsonClient.put(
      `https://jsonplaceholder.typicode.com/posts/${postNum}`,
      recycledPost
    )

    console.log(res.statusCode)
  } catch (err) {
    console.error(err)
  }
})()

See Options for more information regarding clientOptions and requestOptions.

API

new ReqiClient([clientOptions])

Creates a new client with the supplied clientOptions overriding defaults.

request(requestOptions[, body=null])

  • requestOptions: <Object> See requestOptions
  • body: <Object> | <string> | <Buffer> | <stream> An acceptable request body.

request(url[, body=null])

  • url: <string> | <URL> A parsable WHATWG input URL, or URL class.
  • body: <Object> | <string> | <Buffer> | <stream> An acceptable request body.

Options

clientOptions

  • clientOptions: <Object>
    • redirect: <boolean> | <number> Controls request redirection. If a positive number is passed, the redirect option will delimit the maximum redirect amount. Upon being set to 'true', all redirects will be followed.
    • retry: <boolean> | <number> Control request retries. If a positive number is passed, the retry option will delimit the maximum retry amount. Upon being set to 'true', retry attempts will be made until a success code is recieved.
    • retryCodes: number | <number[]> HTTP response code(s) to retry upon i.e. 101 or [426, 429].
    • maxWait: <number> The maximum number of seconds to wait before retrying a request. Deals primarily with rate limits.
    • json: <boolean> Enables or disables automatic request and response body parsing. If enabled, 'true', both bodies sent and recieved by the client are serialized and parsed, respectively.

Reqi gives you the option to control retries and redirects, as well as the ability to enable automatic body parsing.

const retryClient = new ReqiClient({ retry: 3, retryCodes: [429] })

By default, retries, redirects, and body parsing are disabled.

Client options are mutable too!

// for example
client.clientOptions.retry = 1

Default ReqiClient Configuration:

this.clientOptions = {
  redirect: false,
  retry: false,
  retryCodes: [],
  maxWait: 3, // seconds
  json: false
}

These clientOptions are bound to the request client and allow for subsequent requests without reconfiguration.

requestOptions

  • requestOptions: <Object>
    • url: <string> | <URL> (Required) A parsable WHATWG input URL, or URL class.

Just like what you're used to with Node Core, Reqi supports all core HTTP/HTTPS request options, with a few defaults:

  • method: the desired HTTP request method, defaulting to 'GET'.
  • port: the desired HTTP host port. If no port is provided, Reqi will use either a 80 or 443 value depending on the request protocol.

For more information on the supported requestOptions, consult the following Node.js documentation:

Contributing

Contributing via DCO 1.1.

License

Licensed under the MIT License. See the LICENSE file for more details.