1.0.10 • Published 2 years ago

commons-generic-http v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

HTTP Common module for http calls

Supported modules as of this version:

  1. Axios

Quick Start

Step 1: Set the Config (Skip if you are ok with default config)

// During the app initialization step (usually before anyapi call) call setConfig method of commons-generic-http
// If you want details for few apis, call this method again

const httpRequest = require('commons-generic-http')
httpRequest.setConfig({
    retry: 3,
    logAxiosDetails: false,
    retryAfter: 10,
    timeout: 15000,
    logLevel: "info",
})

The default config is as below

Config KeyDefault ValueOther ExamplesDescription
retry3any numberThe number of times you want to repeat the api call in case of failure
logAxiosDetailsfalsetrue | falseIf set to true it will log axios in more details(for debugging purpose)
retryAfter10any numberNumber of seconds to wait before retrying the failed api call
logLevellogdebug | log | warn | error | noneLevel of log you need to set
timeout15any numberThe number of Milliseconds you need to wait for the server to respond back

Step 2: Call APIs anywhere in your app

const token = 'exyaukv93976kfds87s9'
const httpRequest = require('commons-generic-http')

const response = await httpRequest.httpCall({
    method: 'GET',
    headers: {
        'Authorization': `Bearer ${token}`
    },
    url: 'http://api.some-endpoint.com',
    proxy: false, // Pass in false in case of not using proxy
    data: {}// data for POST method
})

// Required fields: url, method, proxy

httpCall method will accept an object of type AxiosRequestConfig

AxiosRequestConfig: This is supported by Axios official package so look for more details in their package here

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.10

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago