Socket
Book a DemoInstallSign in
Socket

http-client-retry

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-client-retry

HTTP client package for Typescript projects.

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

http-client-retry

This is an HTTP client module for Node JS projects that provides applications a unified way to communicate over HTTP with retry logic.

These instructions will help you integrate this module with your Node JS application.

Prerequisites

You'll need a Node JS runtime with NPM installed wherever you plan to run the npm install command in the context of your microservice. Additionally, this module will work for NodeJS modules written in pure Javascript, however this module is intended to be use in a project written in Typescript. The following instructions take for granted that consuming Node JS applications are written in Typescript.

Installing

A step by step series of examples that tell you how to get this module integrated to your Node JS microservice.

  • Install via NPM command-line-interface

     npm install http-client-retry@version
    
  • Add the following modules as a dependencies in your Node JS microservice project.

    a. Add the following lines to the dependencies section of your package.json file where X.X.X is ...the version you want to include.

    "http-client-retry": "X.X.X"
    

Usage

Import an httpClient instance

import { httpClient } from "http-client-retry"

Create IHttpClientOptions for your HTTP request.

const httpClientOptions: IHttpClientOptions = {
    uri: "http://localhost",
    method: "GET"
};

Pass the client options you created to the call method of the HTTP client instance you imported and await the Result object.

const response: Response = await httpClient.call(httpClientOptions);

IHttpClientOptions Overview

This is the only parameter required to pass into the call method of the Http Client. Please pay special attention to the behavior the retryableStatusCodes property. There are HTTP status codes that will be retried by default.

ParameterTypeIs OptionalPurposeDefault Value
uristringfalseURL of the resource you are requestingN/A
methodstringfalseThe HTTP verb you want to use. Available values: "GET", "POST", "PUT", "DELETE", "HEAD"N/A
bodyanytrueObject to be sent in body of HTTP requestundefined
automaticallyParseJsonbooleantrueAutomatically parse the JSON in the response bodytrue
resolveWithFullResponsebooleantrueReturn the entire Response object or just the Response.body propertytrue
headersIHttpHeader[]trueCollection of key-value pairs added HTTP request[{"X-Request-ID": <GUID> }]
authIHttpAuthOptionstrueHTTP authorization optionsundefined
requestAttemptsCountnumbertrueHow many times to attempt the HTTP request1
retryIntervalInMillisecondsnumbertrueHow long to wait between HTTP request attempts (in milliseconds)1000
retryableStatusCodesnumber[]trueList of HTTP status codes to append to the default value that when returned to the client will be retried[502, 503, 504]

IHttpHeader Overview

This option allows you to pass in an array of key-value pairs where the key is of type string and the value is of type any.

By default a custom header of "X-Request-ID": <GUID> will be added to each http client request.

Any headers you provide in the IHttpClientOptions object will be added to the default header collection which contains the "X-Request-ID" header mentioned above.

IHttpAuthOptions Overview

If passed as an option, auth should contain the following values:

  • user - Basic authentication username
  • pass - Basic authentication password
  • bearer (optional) - Bearer access token

Without providing a bearer value, Basic authentication will be used.

Bearer authentication is supported, and is activated when the bearer value is available. The value may be either a String or a Function returning a String. Using a function to supply the bearer token is particularly useful if used in conjunction with defaults to allow a single function to supply the last known token at the time of sending a request, or to compute one on the fly.

Built With

  • npm - Dependency Management
  • NodeJS - Runtime

Authors

Keywords

http

FAQs

Package last updated on 26 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.