Bun

interface

BunFetchRequestInit

interface BunFetchRequestInit

BunFetchRequestInit represents additional options that Bun supports in fetch() only.

Bun extends the fetch API with some additional options, except this interface is not quite a RequestInit, because they won't work if passed to new Request(). This is why it's a separate type.

  • body?: null | BodyInit

    A BodyInit object or null to set request's body.

  • cache?: RequestCache

    A string indicating how the request will interact with the browser's cache to set request's cache.

  • credentials?: RequestCredentials

    A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials.

  • decompress?: boolean

    Control automatic decompression of the response body. When set to false, the response body will not be automatically decompressed, and the Content-Encoding header will be preserved. This can improve performance when you need to handle compressed data manually or forward it as-is. This is a custom property that is not part of the Fetch API specification.

    // Disable automatic decompression for a proxy server
    const response = await fetch("https://example.com/api", {
      decompress: false
    });
    // response.headers.get('content-encoding') might be 'gzip' or 'br'
    
  • headers?: HeadersInit

    A Headers object, an object literal, or an array of two-item arrays to set request's headers.

  • integrity?: string

    A cryptographic hash of the resource to be fetched by request. Sets request's integrity.

  • keepalive?: boolean

    A boolean to set request's keepalive.

  • method?: string

    A string to set request's method.

  • mode?: RequestMode

    A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode.

  • priority?: RequestPriority
  • protocol?: 'http2' | 'http1.1' | 'h2' | 'h1'

    Force the underlying HTTP version. "http2" advertises only h2 in the TLS ALPN list and the request fails with HTTP2Unsupported if the server doesn't select it. "http1.1" pins the request to HTTP/1.1, overriding --experimental-http2-fetch / BUN_FEATURE_FLAG_EXPERIMENTAL_HTTP2_CLIENT if set. Omit to use the default (h2 is offered iff the flag is on).

    Requires https. This is a custom property that is not part of the Fetch API specification.

  • proxy?: string | { headers: HeadersInit; url: string }

    Override http_proxy or HTTPS_PROXY This is a custom property that is not part of the Fetch API specification.

    Can be a string URL or an object with url and optional headers.

    // String format
    const response = await fetch("http://example.com", {
     proxy: "https://username:password@127.0.0.1:8080"
    });
    
    // Object format with custom headers sent to the proxy
    const response = await fetch("http://example.com", {
     proxy: {
       url: "https://127.0.0.1:8080",
       headers: {
         "Proxy-Authorization": "Bearer token",
         "X-Custom-Proxy-Header": "value"
       }
     }
    });
    

    If a Proxy-Authorization header is provided in proxy.headers, it takes precedence over credentials parsed from the proxy URL.

  • redirect?: RequestRedirect

    A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect.

  • referrer?: string

    A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer.

  • referrerPolicy?: ReferrerPolicy

    A referrer policy to set request's referrerPolicy.

  • s3?: S3Options

    Override the default S3 options

    const response = await fetch("s3://bucket/key", {
      s3: {
        accessKeyId: "AKIAIOSFODNN7EXAMPLE",
        secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
        region: "us-east-1",
      }
    });
    
  • signal?: null | AbortSignal

    An AbortSignal to set request's signal.

  • tls?: BunFetchRequestInitTLS

    Override the default TLS options

  • unix?: string

    Make the request over a Unix socket

    const response = await fetch("http://example.com", { unix: "/path/to/socket" });
    
  • verbose?: boolean

    Log the raw HTTP request & response to stdout. This API may be removed in a future version of Bun without notice. This is a custom property that is not part of the Fetch API specification. It exists mostly as a debugging tool

  • window?: null

    Can only be null. Used to disassociate request from any Window.