https://github.com/muke1908/fetch22
a wrapper to use fetch more efficiently and easily.
https://github.com/muke1908/fetch22
Last synced: about 2 months ago
JSON representation
a wrapper to use fetch more efficiently and easily.
- Host: GitHub
- URL: https://github.com/muke1908/fetch22
- Owner: muke1908
- License: mit
- Created: 2020-07-18T15:53:10.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-31T13:42:13.000Z (over 1 year ago)
- Last Synced: 2024-09-15T06:41:40.550Z (over 1 year ago)
- Language: TypeScript
- Size: 245 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A lightweight wrapper to use fetch more efficiently and easily and with better error handling, and this is promisified!



---
## Basic usage:
[](https://codesandbox.io/s/tender-field-22tkq?fontsize=14&hidenavigation=1&theme=dark)
import from CDN
```
```
Or from NPM,
```
import fetch from 'fetch-req';
```
```
const someFunction = async ()=> {
const respGET = await fetch.get('http://dummy.restapiexample.com/api/v1/employees');
const respPOST = await fetch.post('http://dummy.restapiexample.com/api/v1/employees', {
'dummyData': 'Mukesh'
})
}
```
## Additional methods:
**1. Poll** - call an endpoint and handle response in interval.
```
const endpoint = () => fetch.get('http://dummy.restapiexample.com/api/v1/employees');
const poll = fetch.poll(endpoint, callback, 1000);
poll.pause(); // Pause polling
poll.resume(); // Resume polling
poll.updateInterval(1000); // Update the interval, set it to 1000ms
```
**Note:** This doesn't use `setInterval`, and it **prevents the race conditions** because, it makes the next call exactly after given time(in ms)
from the time last response received.
**2. Retry** - Retry no of times in case request fails.
```
const resp = await fetch.retry(3).get('http://dummy.restapiexample.com/api/v1/employees');
```