Http Service
Http Service from Resourge provides a simple and flexible API for making HTTP requests, handling responses, and managing errors in your JavaScript applications. It is ideal for interacting with REST APIs and handling network operations efficiently.
Features
Section titled “Features”- Simple API for GET, POST, PUT, DELETE, and more
- Built-in error handling and response parsing
- Support for request/response interceptors
- Works with any JavaScript framework or vanilla JS
- TypeScript support
Installation
Section titled “Installation”npm install @resourge/http-service# oryarn add @resourge/http-service
Basic Usage
Section titled “Basic Usage”import { http } from '@resourge/http-service';
// GET requesthttp.get('/api/users').then(users => { console.log(users);}).catch(error => { console.error(error);});
// POST requesthttp.post('/api/users', { name: 'Alice' }).then(user => { console.log(user);});
Using Interceptors
Section titled “Using Interceptors”http.interceptors.request.use(config => { // Modify request config (e.g., add auth token) config.headers['Authorization'] = 'Bearer token'; return config;});
http.interceptors.response.use(response => { // Handle or transform response return response;});