Skip to content

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.

  • 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
Terminal window
npm install @resourge/http-service
# or
yarn add @resourge/http-service
import { http } from '@resourge/http-service';
// GET request
http.get('/api/users').then(users => {
console.log(users);
}).catch(error => {
console.error(error);
});
// POST request
http.post('/api/users', { name: 'Alice' }).then(user => {
console.log(user);
});
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;
});