BrowserHttpClient.ts
BrowserHttpClient.ts overview
Section titled “BrowserHttpClient.ts overview”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
Exports Grouped by Category
Section titled “Exports Grouped by Category”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>}>Since v4.0.0
RequestInit
Section titled “RequestInit”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 RequestInitSince v4.0.0
layerFetch
Section titled “layerFetch”Layer that provides an HttpClient implementation backed by the configured Fetch function.
Signature
declare const layerFetch: Layer.Layer<HttpClient.HttpClient, never, never>Since v4.0.0
layers
Section titled “layers”layerXMLHttpRequest
Section titled “layerXMLHttpRequest”Layer that provides an HttpClient implementation backed by the browser XMLHttpRequest API.
Signature
declare const layerXMLHttpRequest: Layer.Layer<HttpClient.HttpClient, never, never>Since v4.0.0
models
Section titled “models”XHRResponseType (type alias)
Section titled “XHRResponseType (type alias)”Allowed response body modes for the browser XHR HTTP client.
Signature
type XHRResponseType = "arraybuffer" | "text"Since v4.0.0
references
Section titled “references”CurrentXHRResponseType
Section titled “CurrentXHRResponseType”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
XHRResponseTypefor the allowed response body modeswithXHRArrayBufferfor scoping XHR response handling toArrayBuffer
Signature
declare const CurrentXHRResponseType: Context.Reference<XHRResponseType>Since v4.0.0
withXHRArrayBuffer
Section titled “withXHRArrayBuffer”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>Since v4.0.0
services
Section titled “services”XMLHttpRequest (class)
Section titled “XMLHttpRequest (class)”Service tag for the XMLHttpRequest constructor used by the browser XHR HTTP client.
Signature
declare class XMLHttpRequestSince v4.0.0