https://github.com/melon-studio/fetchs
Fetchs is a powerful and flexible HTTP client library for making network requests in JavaScript applications.
https://github.com/melon-studio/fetchs
http javascript typescript
Last synced: about 1 year ago
JSON representation
Fetchs is a powerful and flexible HTTP client library for making network requests in JavaScript applications.
- Host: GitHub
- URL: https://github.com/melon-studio/fetchs
- Owner: Melon-Studio
- License: mit
- Created: 2023-12-16T17:38:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-29T15:52:19.000Z (about 1 year ago)
- Last Synced: 2025-03-13T17:19:32.810Z (about 1 year ago)
- Topics: http, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Fetchs
Fetchs is a powerful and flexible HTTP client library for making network requests in JavaScript applications. It provides a wide range of features such as caching, request retrying, request and response interceptors, and timeout handling. Built on top of the native fetch API, Fetchs offers a simple and intuitive interface to handle various HTTP operations with ease.
### Features
- **Multiple HTTP Methods**: Supports all major HTTP methods including GET, POST, PUT, PATCH, DELETE, and HEAD.
- **Caching Mechanism**: Enables caching of responses with customizable time-to-live (TTL) and storage options (memory or localStorage).
- **Request Retrying**: Automatically retries failed requests based on specified status codes and retry configurations.
- **Interceptors**: Allows adding custom logic before sending requests and after receiving responses.
- **Timeout Handling**: Sets a timeout for requests to prevent hanging requests.
- **Customizable Configuration**: Provides a global configuration object that can be customized for each request.
### Installation
Download the release to your project.
### Basic Usage
```javascript
import { Fetchs, FetchsConfig } from 'fetchs';
// Create a new instance of Fetchs with optional global configuration
const fetchs = new Fetchs({
baseUrl: 'https://www.example.com',
timeout: 3000,
headers: {
'Authorization': 'Bearer YourAccessToken'
}
});
// Define the request configuration
const config: FetchsConfig = {
method: 'GET',
responseType: 'json'
};
// Execute a request
fetchs.executeRequest<{ message: string }>('/data', config)
.then(response => {
console.log('Response:', response);
})
.catch(error => {
console.error('Error:', error);
});
```
For more details and advanced usage, refer to the [documentation](#) (Not yet open).
### License
This project is licensed under the MIT License - see the [LICENSE](LICENSE.txt) file for details.