Xior is a lightweight HTTP request library based on the native fetch API, designed to feel familiar for those used to axios. It offers an array of features including support for plugins and a similar API, while ensuring excellent performance and strong type safety. Ideal for modern web applications.
xior is a lightweight HTTP request library primarily built upon the fetch API, designed to offer developers a plugin-supported environment with an API that closely resembles axios
. This library excels in simplifying HTTP operations while incorporating advanced features for enhancing performance and control.
Key Features
- ⚡ Efficient Use of Fetch: Leverages the built-in fetch API for streamlined communications.
- 📦 Familiar API: Mimics
axios
with methods such asaxios.create
,axios.interceptors
, and supports.get
,.post
,.put
,.patch
,.delete
,.head
, and.options
requests. - ⏳ Extended Functionality: Includes timeout management, request cancellation, and advanced nested query string handling.
- 🧩 Plugin Support: Offers a diverse range of plugins such as error retry, caching, request throttling, and custom plugin capabilities.
- 📏 Lightweight Footprint: With a size of approximately 8KB (Gzip size ~3KB), it remains efficient for modern applications.
- 🔍 Type Safety: Fully unit tested and strongly typed, ensuring reliability and maintainability.
Getting Started
To begin utilizing xior, you can simply import it into your project. Here is a brief example of how to instantiate a xior
instance:
import xior from 'xior';
const xiorInstance = xior.create({
baseURL: 'https://api.example.com/',
headers: {
'Content-Type': 'application/json'
}
});
Example of Request Usage
Performing a GET request is seamless:
async function fetchData() {
const { data } = await xiorInstance.get('/endpoint');
console.log(data);
}
POST requests are similarly straightforward:
async function postData() {
const response = await xiorInstance.post('/endpoint', { key: 'value' });
console.log(response.data);
}
Plugin Overview
The true strength of xior lies in its modular architecture through plugins:
- Error Retry Plugin: Automatically retries failed requests.
- Throttle Plugin: Prevents multiple identical requests from executing simultaneously.
- Cache Plugin: Enables data to be retrieved from cache instead of making additional requests, enhancing performance.
xior is designed to provide an organized and efficient way to manage HTTP requests while minimizing the complexity associated with managing asynchronous operations. Its plugin system allows for rapid adaptability to varying project needs and requirements.
No comments yet.
Sign in to be the first to comment.