mdfetch API Documentation - v1.0.0
    Preparing search index...

    Function fetchHTML

    • Fetches HTML content from a URL with timeout and retry capabilities.

      Features:

      • Configurable timeout with automatic cancellation
      • Exponential backoff retry logic for transient failures
      • Content-type validation (expects HTML)
      • Automatic retry on 5xx errors, but not 4xx errors
      • User-agent header to avoid bot detection

      Parameters

      • url: string

        The URL to fetch HTML from

      • options: FetchOptions = {}

        Optional fetch configuration

        Options for fetching HTML content from URLs.

        • Optionaltimeout?: number

          Request timeout in milliseconds (default: 30000)

        • Optionalretries?: number

          Number of retry attempts on failure (default: 3)

        • OptionalretryDelay?: number

          Delay between retries in milliseconds (default: 1000)

      Returns Promise<string>

      Promise that resolves to the HTML content as a string

      When the request fails after all retries, times out, or receives non-HTML content

      // Basic usage
      const html = await fetchHTML('https://example.com');

      // With custom timeout and retries
      const html = await fetchHTML('https://example.com', {
      timeout: 60000,
      retries: 5,
      retryDelay: 2000
      });