Skip to content

BrowserHttpClient.ts

Browser implementations of the Effect HttpClient.

This module exposes HTTP client layers for code that runs in a browser. It re-exports the fetch-based Fetch, RequestInit, and layerFetch APIs for the common case where requests use the platform fetch implementation. It also provides an XMLHttpRequest-backed client, including controls for the XHR response type, an overridable XMLHttpRequest constructor service, and the layerXMLHttpRequest layer.

Since v4.0.0



Context reference for the fetch implementation used by the fetch-based HTTP client.

Signature

declare const Fetch: Context.Reference<{
(input: RequestInfo | URL, init?: RequestInit): Promise<Response>
(input: string | URL | Request, init?: RequestInit): Promise<Response>
}>

Source

Since v4.0.0

Service that contains default fetch options for the browser fetch client.

When to use

Use to provide default credentials, cache, redirect, integrity, or other fetch options for browser HTTP requests.

Signature

declare const RequestInit: typeof RequestInit

Source

Since v4.0.0

Layer that provides an HttpClient implementation backed by the configured Fetch function.

Signature

declare const layerFetch: Layer.Layer<HttpClient.HttpClient, never, never>

Source

Since v4.0.0

Layer that provides an HttpClient implementation backed by the browser XMLHttpRequest API.

Signature

declare const layerXMLHttpRequest: Layer.Layer<HttpClient.HttpClient, never, never>

Source

Since v4.0.0

Allowed response body modes for the browser XHR HTTP client.

Signature

type XHRResponseType = "arraybuffer" | "text"

Source

Since v4.0.0

Context reference for the XMLHttpRequest.responseType used by the browser XHR HTTP client, defaulting to "text".

When to use

Use when you need XHR-backed HTTP requests to receive response bodies as text or raw ArrayBuffer values.

See

  • XHRResponseType for the allowed response body modes
  • withXHRArrayBuffer for scoping XHR response handling to ArrayBuffer

Signature

declare const CurrentXHRResponseType: Context.Reference<XHRResponseType>

Source

Since v4.0.0

Runs an effect with CurrentXHRResponseType set to "arraybuffer" so the XHR HTTP client receives response bodies as ArrayBuffer values.

Signature

declare const withXHRArrayBuffer: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>

Source

Since v4.0.0

Service tag for the XMLHttpRequest constructor used by the browser XHR HTTP client.

Signature

declare class XMLHttpRequest

Source

Since v4.0.0