https://github.com/rudyhuynh/higher-order-fetch
https://github.com/rudyhuynh/higher-order-fetch
compose fetch fetch-api higher-order-functions pipe
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rudyhuynh/higher-order-fetch
- Owner: rudyhuynh
- License: mit
- Created: 2019-07-10T15:49:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-24T09:30:51.000Z (over 4 years ago)
- Last Synced: 2025-03-16T16:10:02.340Z (3 months ago)
- Topics: compose, fetch, fetch-api, higher-order-functions, pipe
- Language: JavaScript
- Homepage: https://rudyhuynh.github.io/higher-order-fetch/
- Size: 1.33 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HIGHER-ORDER FETCH
Using `window.fetch()` with some handful composable logic.
## Why you need this
This library provides a set of handful `fetch` enhancement as well as gives you the idea to create a `fetch` method that:
- Fetch data from server, of course
- Enhanced but remained the familiarity of [the Fetch API that documented and provided by the browsers](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch), so that everyone can quickly understand and use it.
- The enhancement can be easily managed, opt in or out depend on the need of your project.## Installation
```
npm install higher-order-fetch
```or
```
yarn add higher-order-fetch
```## How to use
Step 1: Compose your fetch:
```js
// fetchHelper.js
import { defaultHeadersHOF } from "higher-order-fetch/lib/defaultHeaders";
import { onErrorRetryHOF } from "higher-order-fetch/lib/onErrorRetry";
import { myHOF } from "./myHOF";
import pipe from "higher-order-fetch/lib/utils/pipe";const fetchHelper = {
fetch: pipe(
onErrorRetryHOF,
defaultHeadersHOF,
myHOF
)(window.fetch)
};
export default fetchHelper;
```Step 2: Use it
```js
// somewhere-that-need-to-fetch-data.js
import fetchHelper from "./path/to/fetchHelper.js";fetchHelper.fetch("http://my.url/data").then(/* ... */);
```## Example
Checkout [the example](https://github.com/rudyhuynh/higher-order-fetch/tree/master/example) for a recommended fetch setup and usage
## API
[https://rudyhuynh.github.io/higher-order-fetch/identifiers.html](https://rudyhuynh.github.io/higher-order-fetch/identifiers.html)
## LISCENE
MIT