Platform notes
Set up Effetch for browsers and React Native.
This page covers what to know, and what to set up, when you run Effetch in a browser or in React Native.
Effetch has no platform-specific imports or builds, and runs wherever Effect's
HttpClient does: browsers, React Native, Node 20 or newer, Bun and Deno.
Two platforms need a little setup.
Browsers
Effect's HttpClient adds traceparent and b3 tracing headers to every
request. Cross-origin calls to APIs that don't allow those headers then fail
the CORS preflight. Turn propagation off in the layer that makes the client,
and it applies to all its calls:
import * as from "effect/http/FetchHttpClient";
import * as from "effect/http/HttpClient";
import * as from "effect/Layer";
import { } from "@monarcode/effetch";
export class extends .<>()("Api", {
: "https://api.example.com",
}) {}
export const = ..(
.(.(.)(false)),
.(.),
);In a browser, a relative path without a baseUrl is resolved against the
page's URL.
React Native
React Native differs from the other platforms in these ways:
- Effetch doesn't use
URLitself. Effect'sHttpClientdoes, includingsearchParams. Expo provides a standardURL. In a React Native app without Expo, install a polyfill such asreact-native-url-polyfill. - Effetch and Effect use package
exports(effect/http/HttpClient,@monarcode/effetch/plugins). Metro resolves them by default from React Native 0.79 (Expo SDK 53). On older versions, setresolver.unstable_enablePackageExports = trueinmetro.config.js. FetchHttpClient.layeruses the globalfetch.- React Native's
fetchdoesn't stream response bodies, soapi.sse,api.ndjsonand stream endpoints fail with aDecodeErrorthere. In Expo, provide thefetchfromexpo/fetch, which streams, asFetchHttpClient.Fetch:Layer.succeed(FetchHttpClient.Fetch)(expoFetch as typeof globalThis.fetch). - To upload a file a picker gave you, send its
{ uri, name, type }in aFetch.UploadFilefield (see Upload files). React Native'sFormDatareads the file from disk byuri, and can't send aBlob. - Metro's terminal drops
console.groupCollapsedand everything inside it, soconsoleLoggerdoesn't collapse its groups in React Native (see the details in Log to the console).