This folder contains detailed documentation and examples for the @neabyte/fetch library.
- Examples - Code examples and usage patterns
- API Reference - Detailed API documentation
- TypeScript Types - Type definitions and interfaces
- Guides - Step-by-step guides for common use cases
For installation and basic setup, see the main README.
fetch.get(url, options?)- GET requestfetch.post(url, body?, options?)- POST requestfetch.put(url, body?, options?)- PUT requestfetch.patch(url, body?, options?)- PATCH requestfetch.delete(url, options?)- DELETE requestfetch.head(url, options?)- HEAD requestfetch.options(url, options?)- OPTIONS requestfetch.trace(url, options?)- TRACE request
// Main class and error handling
import fetch, { FetchError } from '@neabyte/fetch'
// TypeScript types
import type { AuthConfig } from '@neabyte/fetch'type FetchRequestBody =
| string
| FormData
| URLSearchParams
| Blob
| ArrayBuffer
| Uint8Array
| Record<string, unknown>
type FetchResponseType = 'auto' | 'json' | 'text' | 'buffer' | 'blob'
interface BalancerConfig {
/** Array of endpoint URLs to balance across */
endpoints: string[]
/** Load balancing strategy to use */
strategy: 'fastest' | 'parallel'
}
interface ForwarderEndpoint<T = unknown> {
/** HTTP method for forwarding */
method: string
/** URL to forward to */
url: string
/** Headers to include in forwarded request */
headers?: Record<string, string>
/** Request body to forward - can be static data or a function that receives original response */
body?: ForwarderBodyFunction<T> | Record<string, unknown> | string | number | boolean | null
/** Timeout for this forwarder endpoint (ms) */
timeout?: number
/** Number of retry attempts for this forwarder endpoint */
retries?: number
/** SSL pinning hashes for certificate validation */
sslPinning?: string[]
}
interface FetchOptions {
/** Authentication configuration */
auth?: AuthConfig
/** Load balancer configuration */
balancer?: BalancerConfig
/** Base URL for relative requests */
baseURL?: string
/** Request body data */
body?: FetchRequestBody
/** Enable file download mode */
download?: boolean
/** Filename for downloads */
filename?: string
/** Response forwarding configuration */
forwarder?: ForwarderEndpoint[]
/** Additional request headers */
headers?: Record<string, string>
/** Maximum transfer rate in bytes per second (for downloads/uploads) */
maxRate?: number
/** Progress callback for downloads */
onProgress?: (percentage: number) => void
/** Number of retry attempts */
retries?: number
/** Response parsing type */
responseType?: FetchResponseType
/** Abort signal for cancellation */
signal?: AbortSignal
/** SSL pinning hashes for certificate validation */
sslPinning?: string[]
/** Enable streaming response */
stream?: boolean
/** Request timeout in milliseconds */
timeout?: number
/** Enable cookie management */
withCookies?: boolean
}Guides with markdown explanations and TypeScript code:
-
General Usage - HTTP methods and common usage patterns
-
Authentication - Basic, Bearer, and API key authentication
-
SSL Pinning - SSL certificate pinning for enhanced security
-
Request Balancer - Load balancing and failover examples
-
Response Forwarder - Response forwarding and observability examples
-
Progress Tracking - Upload and download progress
-
Streaming - Real-time data streaming / chunking
- Cookie Management - Cookie handling and management
- Advanced Usage - Configuration options and patterns
- Error Handling - Error handling patterns
cd <path>/Fetch
npx tsx ./examples/filename.ts- Request Balancer - Load balancing strategies and patterns
- Response Forwarder - Response forwarding and observability