1.0.0 • Published 2 months ago

@lite-base/http v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Installation

npm install @lite-base/http
import http from '@lite-base/http';

// Create http instance with configuration options
const http = new http({
  baseURL: 'https://api.example.com',
  timeout: 15000,
  headers: {
    'Content-Type': 'application/json',
    // Add other default headers if needed
  },
  requestInterceptor: config => {
    // Modify config before sending the request
    // e.g., add token
    return config;
  },
  responseInterceptor: responseData => {
    // Perform operations on the response data before handling it
    return responseData;
  },
});

// Make a request using the instance
http.request('GET', '/data')
  .then(data => {
    console.log('Successfully retrieved data:', data);
  })
  .catch(error => {
    console.error('Request failed:', error);
  });