Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akr4/physalis-fetch
Fetch with timeout support and an ability to set default settings
https://github.com/akr4/physalis-fetch
fetch-api typescript
Last synced: about 1 month ago
JSON representation
Fetch with timeout support and an ability to set default settings
- Host: GitHub
- URL: https://github.com/akr4/physalis-fetch
- Owner: akr4
- License: mit
- Created: 2020-06-12T10:02:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T15:01:46.000Z (almost 2 years ago)
- Last Synced: 2024-04-16T11:07:36.593Z (7 months ago)
- Topics: fetch-api, typescript
- Language: TypeScript
- Homepage:
- Size: 520 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# physalis-fetch
Fetch with timeout support and an ability to set default settings
## Installation
Add the following line to the `.npmrc` in your project root.
```
@akr4:registry=https://npm.pkg.github.com/akr4
```Then, install the package.
```
npm install @akr4/physalis-fetch
```## Usage
Basic
```typescript
import { makeFetch } from '@akr4/physalis-fetch';const fetch = makeFetch();
const response = await fetch('/foo');
```With default settings
```typescript
import { makeFetch } from '@akr4/physalis-fetch';const fetch = makeFetch({
timeout: 30 * 1000,
headers: { 'X-Custom-Header': 'foo' },
});
const response = await fetch('/foo');
```With merged headers
```typescript
import { makeFetch, mergeHeaders } from '@akr4/physalis-fetch';const fetch = makeFetch(
{
timeout: 30 * 1000,
headers: { 'X-Custom-Header': 'foo' },
},
mergeHeaders,
);const response = await fetch('/foo', {
headers: { 'X-Custom-Header2': 'bar' },
});
```Evaluate options on every fetch
```typescript
import { makeFetch } from '@akr4/physalis-fetch';const fetch = makeFetch((init) => ({
timeout: 30 * 1000,
headers: { 'X-Custom-Header': getCustomHeaderValue() },
}));
```## Release procedure
1. Bump version
2. Publish```bash
npm publish
```