Fetch Client API Documentation - v1.1.1
    Preparing search index...

    Class ApiRequest

    HTTP Request with advanced retry logic and exponential backoff

    Handles HTTP request execution with sophisticated retry mechanisms, automatic body serialization, URL building, and timeout management. Implements exponential backoff with jitter to prevent thundering herd problems.

    // Create and execute a request
    const request = new ApiRequest({
    method: 'POST',
    url: '/api/users',
    baseURL: 'https://api.example.com',
    data: { name: 'John', email: 'john@example.com' },
    retry: { maxRetries: 3, delay: 1000 },
    timeout: 10000
    });

    try {
    const response = await request.send();
    console.log('Success:', response.status);
    } catch (error) {
    console.error('Request failed:', error);
    }
    Index

    Constructors

    • Create a new ApiRequest instance

      Parameters

      Returns ApiRequest

      Initializes a new HTTP request with all necessary configuration and prepares headers, parameters, and other settings.

      const request = new ApiRequest({
      method: 'GET',
      url: '/users',
      baseURL: 'https://api.example.com',
      params: { page: 1, limit: 10 },
      headers: { 'Authorization': 'Bearer token123' },
      timeout: 5000
      });

    Properties

    headers: Headers

    HTTP headers for the request

    Automatically populated from config.headers and includes content-type headers for JSON data

    params: URLSearchParams

    URL query parameters

    Automatically URL-encoded parameters from config.params

    data: Body

    Request body data

    Raw data that will be serialized based on type

    method: HttpMethod

    HTTP method for the request

    One of GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS

    retry?: number | RetryConfig

    Retry configuration for failed requests

    Can be a number (simple retry count) or detailed config object

    url: string

    Request URL path

    Will be combined with baseURL if provided

    timeout?: number

    Request timeout in milliseconds

    Request will be aborted if it takes longer than this

    Complete request configuration

    Methods

    • Execute the request with retry logic and error handling

      Returns Promise<Response>

      Promise resolving to the HTTP Response

      When request fails after all retry attempts

      Executes the HTTP request with sophisticated retry logic:

      • Implements exponential backoff with jitter
      • Handles timeouts with AbortController
      • Automatically retries on network errors and server errors
      • Converts native errors to ApiError instances
      try {
      const response = await request.send();
      if (response.ok) {
      const data = await response.json();
      console.log('Success:', data);
      }
      } catch (error) {
      if (error instanceof ApiError) {
      console.log('API Error:', error.code, error.status);
      }
      }