Introduction
A comprehensive package that provides essential services for web applications.
http-service
http-service
is a comprehensive package that provides essential services for web applications. This package includes BaseHttpService
for making HTTP requests to servers and LoadingService
for managing loading indicators. Together, these services offer a robust solution for handling asynchronous operations and displaying loading feedback.
Installation
Install using Yarn:
yarn add @resourge/http-service
or NPM:
npm install @resourge/http-service
Features
- BaseHttpService: A service for making HTTP requests to servers.
- LoadingService: A service for managing loading indicators in your application.
- Interceptors: Customize request and response configurations with interceptors.
- Configuration: Learn how to configure the
BaseHttpService
for making requests to a server. - Methods: Learn how to make HTTP requests using the
HttpService
class. - Error Handling: Handle errors and exceptions in your application.
Usage
import { BaseHttpService, LoadingService } from '@resourge/http-service';
const HttpService = new BaseHttpService({
baseUrl: 'https://api.example.com',
headers: {
'Authorization ': 'Bearer token123'
}
});
// Show loading indicator
LoadingService.show();
// Make a requests
const response = await HttpService.get('/getProducts', { productId: 1 });
await HttpService.post('/postProducts', { productId: 1, productName: 'apple' });
await HttpService.put('/putProducts');
await HttpService.delete('/deleteProducts');
await HttpService.patch('/patchProducts');
await HttpService.upload('POST' | 'PUT', '/uploadProducts', files, data);
// Hide loading indicator
LoadingService.hide();
On This Page