@capriza/http-utils
Advanced tools
Comparing version 0.2.5-beta.2 to 0.2.5-beta.3
{ | ||
"name": "@capriza/http-utils", | ||
"version": "0.2.5-beta.2", | ||
"version": "0.2.5-beta.3", | ||
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,1 @@ | ||
VERSION=0.2.5-beta.1 | ||
VERSION=0.2.5-beta.2 | ||
VERSION=0.2.5-beta.3 |
136
README.md
@@ -1,1 +0,135 @@ | ||
# http-utils | ||
# @capriza/http-utils | ||
## Table Of Contents | ||
- [Overview](#Overview) | ||
- [Installing](#Installing) | ||
- [Configurations](#Configurations) | ||
- [headers](#headers) | ||
- [timeout](#timeout) | ||
- [baseUrl](#baseUrl) | ||
- [auth](#auth) | ||
- [maxRetries](#maxRetries) | ||
- [retryOnNetworkErrors](#retryOnNetworkErrors) | ||
- [retryStatusCodes](#retryStatusCodes) | ||
- [limit](#limit) | ||
- [interval](#interval) | ||
- [maxConcurrent](#maxConcurrent) | ||
- [Instance Methods](#Instance Methods) | ||
- [Examples](#Examples) | ||
## Overview | ||
Http requests client based on [axios](https://www.npmjs.com/package/axios). | ||
Http-Utils supports rate limits, concurrent request, retries request etc. | ||
## Installing | ||
``` | ||
$ npm install @capriza/http-utils | ||
``` | ||
## Configurations | ||
There are several configurations for http-utils instance: | ||
### headers | ||
default: `{ Accept: "application/json", Content-Type: "application/json" }` | ||
### timeout | ||
default: `30000` | ||
Max time (milliseconds) for timeout | ||
### baseUrl | ||
Base url for all of the requests that will be executed by this instance | ||
### auth | ||
Request authentication by username and password. | ||
Should pass in this structure | ||
``` | ||
{ username : 'aaa', password : '123456' } | ||
``` | ||
### maxRetries | ||
default: `0` | ||
max retries in case of failure | ||
### retryOnNetworkErrors | ||
default: `false` | ||
Triggers retry request in case of `ECONNABORTED` or `ECONNRESET` response | ||
### retryStatusCodes | ||
default: `[502, 503, 504]` | ||
Triggers retry request in case of response with status code that equal one of this values | ||
### limit | ||
default: `Infinity` | ||
Define max http requests per interval | ||
### interval | ||
default: `1000` | ||
Time (milliseconds) window for max http requests to be executed | ||
### maxConcurrent | ||
default: `Infinity` | ||
Define max concurrent requests | ||
## Instance Methods | ||
The available instance methods are listed below. | ||
``` | ||
httpClient.get(url, data, props) | ||
``` | ||
``` | ||
httpClient.post(url, data, props) | ||
``` | ||
``` | ||
httpClient.put(url, data, props) | ||
``` | ||
## Examples | ||
Defining instance with base url, 5 http request per 10 seconds, enable 3 retries in case of network error or 502, 503 status codes | ||
``` | ||
const HttpUtils = require('@capriza/http-utils'); | ||
const httpClient = new HttpUtils({ | ||
baseUrl: 'https://api.xxxxxxx.xx', | ||
limit: 5, | ||
inerval: 10 * 1000, | ||
retryOnNetworkErrors: true, | ||
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, | ||
retryOnNetworkErrors: true, | ||
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); | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31920
135