https://github.com/scheibo/wrapr
Middleware wrapper logic for asynchronous functions
https://github.com/scheibo/wrapr
fetch http middleware retry throttle wrapper
Last synced: 2 months ago
JSON representation
Middleware wrapper logic for asynchronous functions
- Host: GitHub
- URL: https://github.com/scheibo/wrapr
- Owner: scheibo
- License: mit
- Created: 2021-07-07T17:05:05.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-07T18:38:31.000Z (over 4 years ago)
- Last Synced: 2025-10-13T11:27:38.363Z (6 months ago)
- Topics: fetch, http, middleware, retry, throttle, wrapper
- Language: TypeScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `wrapr`
[](https://www.npmjs.com/package/wrapr)
Middleware wrapper logic for asynchronous functions.
```js
const wrapr = require('wrapr');
const fetch = require('node-fetch');
wrapr.retrying(wrapr.throttling(fetch))('https://example.com');
wrapr.retrying(wrapr.throttling(args => fetch(args.init, args.url)))({
url: 'https://example.com',
init: {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ foo: 1 }),
},
});
wrapr.retrying(wrapr.throttling(async url => {
try {
return await fetch(url);
} catch (err) {
if (err.message.startsWith('HTTP')) {
throw new wrapr.NonRetryableError(err.message);
} else {
throw err;
}
}
}))('https://example.com');
```
`wrapr` is distributed under the terms of the [MIT License](LICENSE).