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

@capriza/http-utils

v0.4.0

Published

HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication

Downloads

87

Readme

@capriza/http-utils

Table Of Contents

Overview

Http requests client based on axios. The Http-Utils library supports rate limits, concurrent requests, retry requests, request prioritization etc.

Installing

$ npm install @capriza/http-utils

Instance Configuring

An http-utils instance can be configured with the following properties:

headers

default: { Accept: "application/json", Content-Type: "application/json" }

timeout

Maximum duration (milliseconds) allowed for request execution default: 30000

baseUrl

Base URL for requests executed by this instance.

auth

Request authentication by username and password, formatted as follows:

{ username : 'aaa', password : '123456' }

maxRetries

Maximum retries permitted in case of server or network errors, depending on settings of retryStatusCodes and retryNetworkErrors, respectively. default: 0

retryInterval

Amount of time (milliseconds) between retries.

retryNetworkErrors

If one of these values is received as the error code of the response, a retry of the request will be triggered. default: ["ECONNABORTED", "ECONNRESET"]

retryStatusCodes

If one of these values is received as the status code of the response, a retry of the request will be triggered. default: [502, 503, 504]

limit

Maximum number of http requests per interval. default: Infinity

interval

Amount of time (milliseconds) during which the http requests limit can to be executed. default: 1000

maxConcurrent

Number of requests allowed to execute simultaneously default: Infinity

Instance Methods

The available instance methods are listed below:

httpClient.get(url, data, props)
httpClient.post(url, data, props)
httpClient.put(url, data, props)
httpClient.patch(url, data, props)
httpClient.head(url, data, props)

Examples

Instance with base URL, 5 http requests allowed every 10 seconds, allowing 3 retries in case of network or server (502, 503) errors.

const HttpUtils = require('@capriza/http-utils');
const httpClient = new HttpUtils({
    baseUrl: 'https://api.xxxxxxx.xx',
    limit: 5,
    interval: 10 * 1000,
    maxRetries: 3,
    retryStatusCodes: [502, 503]
});

Performing a GET request with priority

const HttpUtils = require('@capriza/http-utils');
const httpClient = new HttpUtils( { baseUrl: 'https://api.xxxxxxx.xx' } );
try {
    let result = await httpClient.get('/route', {}, { priority: true })
    console.log(result);
} catch(ex) {
    console.error(ex);
}

Performing a POST request

const HttpUtils = require('@capriza/http-utils');
const headers = {
   Content-Type: "application/x-www-form-urlencoded"
};

const httpClient = new HttpUtils( {
    baseUrl: 'https://api.xxxxxxx.xx',
    headers,
    retryStatusCodes: [502, 503]
    maxRetries: 3
});
try {
    let result = await httpClient.post('/route', { data: 'sessionId=aaa-bbb-ccc&token=xxx-yyy-zzz' });
    console.log(result);
} catch(ex) {
    console.error(ex);
}