
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
fetch-wrapper
Advanced tools
Wrapper around isomorphic-fetch to retry the request if there is an error
Wrapper around isomorphic-fetch for resending fetch request if there is an error.
$ npm i fetch-wrapper --save
To run the tests first clone the repo:
$ git clone https://github.com/nikhilaravi/fetch-wrapper.git
Run the tests:
$ npm test
The sendRequest
function retries the fetch request if there is an error.
Param | Default | Type | Description |
---|---|---|---|
options | {} | object | REQUIRED: Object specifying the request, onSuccess and onError functions. See below |
retryIntervals | [1000] | array of numbers | OPTIONAL: Time intervals at which to retry the fetch request |
attempt | 0 | number | Do not need to specify |
| Key | Type | Description |
| :------------ |:---------------:| :---------------:| :-----|
| request |function
| function returns a fetch request. Can be created using the create-request helpers (see create-request.js) |
| responseType | enum (text
,json
) | Format of the response. Used to parse the response body using either 'response.text' or 'response.json' methods |
| onSuccess(response) |function
| function to be called with the response when the fetch request returns successfully |
| onError(response) |function
| function to be called when there is an error in the fetch request |
options.onError
will only be called if there is an:
The error object passed to onError is of the form
{
status: '', //either a status code or 'error'
message: ''
}
options.onSuccess
will be called on
The response passed to onSuccess is either the response data (json/text) or in the case of a network/server/parsing error, an error object of the form
{
status: '', //'error'
message: '' // e.g. 'Invalid Response Type' or 'No response body'
}
Helper functions that return a function that send a fetch request
The promise returned by fetch is then resolved inside the sendRequest
function.
Options available for sending get, post and put requests with and without authentication.
The parameters for each helper are outline below in the order they need to be specified.
Param | Default | Type | Description |
---|---|---|---|
url | undefined | string | url of the request |
header | {} | object | Optional header options |
Param | Default | Type | Description |
---|---|---|---|
url | undefined | string | url of the request |
data | null | object | request body which will be stringified |
header | {} | object | Optional header options |
Param | Default | Type | Description |
---|---|---|---|
url | undefined | string | url of the request |
data | null | object | request body which will be stringified |
header | {} | object | Optional header options |
Param | Default | Type | Description |
---|---|---|---|
url | undefined | string | url of the request |
token | undefined | string | Authentication token which will be set to the 'Authorization' key in the request header object |
header | {} | object | Optional further header options |
Param | Default | Type | Description |
---|---|---|---|
url | undefined | string | url of the request |
data | null | object | request body which will be stringified |
token | undefined | string | Authentication token which will be set to the 'Authorization' key in the request header object |
header | {} | object | Optional further header options |
Param | Default | Type | Description |
---|---|---|---|
url | undefined | string | url of the request |
data | null | object | request body which will be stringified |
token | undefined | string | Authentication token which will be set to the 'Authorization' key in the request header object |
header | {} | object | Optional further header options |
import { postReq, sendRequest } from 'fetch-wrapper'
sendRequest({
request: postReq('http://localhost:9009/login', {name: 'name'}), //this should be a function that returns a fetch request
responseType: 'json'
onSuccess: json => { //on success code here },
onError: error => { //on error code here }
})
Collaborators: @besartshyti
FAQs
Wrapper around isomorphic-fetch to retry the request if there is an error
We found that fetch-wrapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.