Documentation Index Fetch the complete documentation index at: https://mintlify.com/sebamar88/bytekit/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The ApiClient class is a powerful, isomorphic HTTP client that works in both Node.js and browsers. It provides automatic retries, circuit breaker patterns, localized error messages, request/response interceptors, and comprehensive logging.
Import
import { ApiClient } from "bytekit" ;
// or
import { ApiClient } from "bytekit/api-client" ;
Constructor
Configuration object for the API client Base URL for all requests
Default headers for all requests
Locale for error messages
Default timeout in milliseconds
Retry configuration (maxAttempts, initialDelayMs, maxDelayMs, backoffMultiplier)
Circuit breaker configuration
Request/response interceptors
Logger instance for request logging
Methods
get
Make a GET request.
get < T >( endpoint : string , options ?: RequestOptions ): Promise < T >
post
Make a POST request.
post < T >( endpoint : string , body ?: unknown , options ?: RequestOptions ): Promise < T >
put
Make a PUT request.
put < T >( endpoint : string , body ?: unknown , options ?: RequestOptions ): Promise < T >
patch
Make a PATCH request.
patch < T >( endpoint : string , body ?: unknown , options ?: RequestOptions ): Promise < T >
delete
Make a DELETE request.
delete < T >( endpoint : string , options ?: RequestOptions ) : Promise < T >
list
Make a paginated list request with filters and sorting.
list < T , TFilter >( endpoint : string , options ?: ListOptions < TFilter > ): Promise < PaginatedResponse < T >>
Usage Example
import { ApiClient } from "bytekit" ;
const api = new ApiClient ({
baseUrl: "https://api.example.com" ,
defaultHeaders: {
"X-API-Key" : process . env . API_KEY
},
locale: "en" ,
retryPolicy: {
maxAttempts: 3 ,
initialDelayMs: 100
},
circuitBreaker: {
failureThreshold: 5 ,
resetTimeoutMs: 60000
}
});
// GET request
const users = await api . get < User []>( "/users" );
// POST request
const newUser = await api . post < User >( "/users" , {
name: "John Doe" ,
email: "john@example.com"
});
// Paginated list with filters
const result = await api . list < User , { status : string }>( "/users" , {
pagination: { page: 1 , limit: 20 },
sort: { field: "createdAt" , order: "desc" },
filters: { status: "active" }
});
Error Handling
import { ApiError } from "bytekit" ;
try {
const data = await api . get ( "/users" );
} catch ( error ) {
if ( error instanceof ApiError ) {
console . error ( `HTTP ${ error . status } : ${ error . message } ` );
console . error ( error . body );
}
}
See Also