Tiny HTTP client for Node.js
- 🚀 Lightweight and fast HTTP client for Node.js
- 💪 Full TypeScript support
- 🔥 Promise based
- ✨ Modern and intuitive API
- 🛡️ Automatic transforms for JSON data
- 🔌 Configurable request and response interceptors
- 📦 Zero dependencies
$ npm install apexio
import { Apexio } from 'apexio'
const apexio = new Apexio({
baseURL: 'https://api.example.com'
})
// Make a GET request
apexio
.get('/users')
.then((response) => {
console.log(response.data)
})
.catch((error) => {
console.error(error)
})
// Make a POST request with JSON data
apexio.post('/users', {
name: 'John',
email: '[email protected]'
})
apexio.get<T = any>(url: string, options?: ApexioRequestOptions): Promise<ApexioResponse<T>>
apexio.post<T = any>(url: string, data?: any, options?: ApexioRequestOptions): Promise<ApexioResponse<T>>
apexio.put<T = any>(url: string, data?: any, options?: ApexioRequestOptions): Promise<ApexioResponse<T>>
apexio.delete<T = any>(url: string, options?: ApexioRequestOptions): Promise<ApexioResponse<T>>
apexio.head<T = any>(url: string, options?: ApexioRequestOptions): Promise<ApexioResponse<T>>
apexio.options<T = any>(url: string, options?: ApexioRequestOptions): Promise<ApexioResponse<T>>
{
// Base URL for the request
baseURL?: string
// Request headers
headers?: {
[key: string]: string
}
// URL parameters to be appended to the URL
params?: any
// Request timeout in milliseconds
timeout?: number
// Response type: 'json' | 'text' | 'stream'
responseType?: ApexioResponseType
}
{
// Response data
data: T
// HTTP status code
status: number
// HTTP status message
statusText: string
// Response headers
headers: IncomingHttpHeaders
// Request configuration used
config: ApexioRequestConfig
}
apexio.post('/api/users', {
name: 'John',
age: 30
})
const params = new URLSearchParams()
params.append('name', 'John')
params.append('age', '30')
apexio.post('/api/users', params)
import FormData from 'form-data'
import fs from 'node:fs'
const form = new FormData()
form.append('file', fs.createReadStream('path/to/file.txt'))
form.append('field', 'value')
apexio.post('/api/upload', form)
const stream = fs.createReadStream('path/to/file')
apexio.post('/api/upload', stream)
// Request interceptor
apexio.interceptors.request.use(
(config) => {
// Modify request config
config.headers['Authorization'] = 'Bearer token'
return config
},
(error) => {
return Promise.reject(error)
}
)
// Response interceptor
apexio.interceptors.response.use(
(response) => {
// Handle response data
return response
},
(error) => {
return Promise.reject(error)
}
)
$ pnpm build
$ pnpm test