Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacraig/request
@jacraig/request is a wrapper around fetch that adds functionality including caching, retry, and timeouts
https://github.com/jacraig/request
ajax api fetch
Last synced: 15 days ago
JSON representation
@jacraig/request is a wrapper around fetch that adds functionality including caching, retry, and timeouts
- Host: GitHub
- URL: https://github.com/jacraig/request
- Owner: JaCraig
- License: apache-2.0
- Created: 2024-03-27T17:59:20.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-10-28T21:03:37.000Z (2 months ago)
- Last Synced: 2024-10-30T00:27:46.192Z (2 months ago)
- Topics: ajax, api, fetch
- Language: TypeScript
- Homepage: https://jacraig.github.io/request/
- Size: 1.08 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# @jacraig/request
[![NPM Publish](https://github.com/JaCraig/request/actions/workflows/node-publish.yml/badge.svg)](https://github.com/JaCraig/request/actions/workflows/node-publish.yml)
`@jacraig/request` is a powerful yet lightweight library designed to simplify HTTP requests using the native `fetch` API while adding functionality such as caching, retry logic, and timeouts. It aims to provide developers with a convenient and flexible solution for handling HTTP requests in JavaScript and TypeScript applications.
## Features
- **Caching**: Cache responses to improve performance and reduce network requests.
- **Retry logic**: Automatically retry failed requests with customizable retry options.
- **Timeouts**: Set timeouts for requests to prevent hanging and improve overall application responsiveness.## Installation
You can install `@jacraig/request` via npm:
```bash
npm install @jacraig/request
```## Usage
Here's a basic example of how you can use `@jacraig/request` to make a fetch request:
```typescript
import { Request } from '@jacraig/request';
let returnValue = await Request.get('https://jsonplaceholder.somewhere.com/post.json').send();
```
In order to use caching, retry logic, or timeouts, you can use the extra methods on the returned Request object to set options:
```typescript
import { Request, StorageMode } from '@jacraig/request';
let returnValue = await Request.get('https://jsonplaceholder.somewhere.com/post.json')
.withStorageMode(StorageMode.StorageAndUpdate)
.withTimeout(5000)
.withRetryAttempts(3)
.send();```
If you prefer to use callbacks instead of promises, you can do so by passing a callback function to the `onSuccess` method:
```typescript
import { Request } from '@jacraig/request';
Request.get('https://jsonplaceholder.somewhere.com/post.json')
.onSuccess((response) => {
console.log(response);
})
.send();```
## Documentation
For more detailed information on how to use `@jacraig/request`, please refer to the [documentation](https://jacraig.github.io/request/) on GitHub Pages.## License
@jacraig/request is licensed under the [Apache 2.0 License](https://github.com/JaCraig/request/blob/main/LICENSE)