HTTP Service
@resourge/http-service
provides essential services to simplify HTTP requests and loading indicators in web applications. It includes:
- BaseHttpService: A flexible wrapper around Fetch API with support for request throttling, file uploads, and interceptors.
- LoadingService: A simple service to manage and listen to loading indicator states across your app.
When to use
Section titled “When to use”Use http-service
when you need a reliable, extendable HTTP client with built-in loading state management, especially for React or other front-end frameworks.
Why use this?
Section titled “Why use this?”- Easy-to-use HTTP methods: GET, POST, PUT, PATCH, DELETE
- Request throttling for GET requests
- File upload support
- Customizable interceptors for requests and responses
- Global loading indicator management
- Event listeners for loading state changes
- Extensible through subclassing
Installation
Section titled “Installation”npm install @resourge/http-service# oryarn add @resourge/http-service
Quick Start
Section titled “Quick Start”import { BaseHttpService } from '@resourge/http-service';
const HttpService = new BaseHttpService({ baseUrl: 'https://api.example.com', headers: { Authorization: 'Bearer token123', },});
// Example: GET requestHttpService.get('/posts/1') .then(response => console.log(response)) .catch(error => console.error(error));
// Example: Show loading indicatorimport { LoadingService } from '@resourge/http-service';
LoadingService.show();// ... perform async tasksLoadingService.hide();