Client Factory & Instances
Technical specifications for createClient() and the HttpClient instance interface.
createClient(config?: ClientConfig): HttpClient
Initializes a new isolated HTTP client instance with optional defaults:
typescript
import { createClient } from 'react-native-fetch-client';
const api = createClient({
baseURL: 'https://api.example.com',
timeout: 5000,
});Default Client Singleton
The default exported object is a pre-instantiated HttpClient with an attached .create() factory method:
typescript
import client from 'react-native-fetch-client';
const res = await client.get('https://api.example.com/items');HttpClient Instance Properties & Methods
HttpClient Methods & Properties
| Property | Type | Default | Description |
|---|---|---|---|
| request<T>(config) | Function | — | Dispatches request through the 16-stage pipeline. Returns Promise<HttpResponse<T>>. |
| get<T>(url, config?) | Function | — | Shorthand for HTTP GET request. |
| post<T>(url, body?, config?) | Function | — | Shorthand for HTTP POST request with automatic JSON body encoding. |
| put<T>(url, body?, config?) | Function | — | Shorthand for HTTP PUT request with automatic JSON body encoding. |
| patch<T>(url, body?, config?) | Function | — | Shorthand for HTTP PATCH request with automatic JSON body encoding. |
| delete<T>(url, config?) | Function | — | Shorthand for HTTP DELETE request. |
| safe | SafeHttpClient | — | Go/Rust style safe request methods returning [data, error] tuples. |
| stream(url, options?) | AsyncGenerator<StreamEvent> | — | SSE and chunk streaming generator. |
| upload<T>(url, file, options?) | Function | — | Multipart file and FormData upload helper with progress. |
| poll<T>(url, options) | Function | — | Polling helper executing requests until predicate condition is matched. |
| paginate | PaginateHelper | — | Pagination traversal helper supporting page, offset, cursor, and linkHeader. |
| cache | CacheManager | — | In-memory LRU cache manager instance attached to the client. |
| interceptors | { request, response } | — | Interceptor managers for registering request and response middleware. |