Skip to content

Latest commit

 

History

History
160 lines (129 loc) · 5.27 KB

File metadata and controls

160 lines (129 loc) · 5.27 KB

Documentation

This folder contains detailed documentation and examples for the @neabyte/fetch library.

📚 Contents

  • 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

🚀 Quick Start

For installation and basic setup, see the main README.

🔧 Available Methods

  • fetch.get(url, options?) - GET request
  • fetch.post(url, body?, options?) - POST request
  • fetch.put(url, body?, options?) - PUT request
  • fetch.patch(url, body?, options?) - PATCH request
  • fetch.delete(url, options?) - DELETE request
  • fetch.head(url, options?) - HEAD request
  • fetch.options(url, options?) - OPTIONS request
  • fetch.trace(url, options?) - TRACE request

Import & Usage

// Main class and error handling
import fetch, { FetchError } from '@neabyte/fetch'

// TypeScript types
import type { AuthConfig } from '@neabyte/fetch'

Configuration Options

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
}

📖 Examples

📚 Documentation & Examples

Guides with markdown explanations and TypeScript code:

🚧 Pending Examples

💻 How To Run

cd <path>/Fetch
npx tsx ./examples/filename.ts

🏗️ Architecture

🔗 Links