Clients
Client configuration
Look up an option a client accepts.
This page lists the options you can pass when you declare a client. The
config of Fetch.Service takes the same options as Fetch.make (see
Fetch.Service or Fetch.make).
Example
Here's a client with all of the options:
import * as from "effect/Config";
import * as from "effect/Schema";
import { } from "@monarcode/effetch";
import { , , , } from "@monarcode/effetch/plugins";
const = .({ : ., : . });
class extends .<>()(
"SessionExpired",
{ : . },
) {}
const : { ?: string } = {};
export class extends .<>()("Api", {
: .("API_URL"),
: { "x-client": "web" },
: ,
: { 401: },
: [
(),
(),
({ : "10 seconds" }),
({ : () => . }),
],
}) {}Options
Every option is optional:
| Option | What it's for |
|---|---|
baseUrl | Where the API lives. It's put in front of every path that isn't a full http(s):// URL. Pass a string, or an Effect that's run once when the client is built, such as a Config. It can't contain a query string or a fragment. |
headers | Headers sent with every request. A call's header with the same name wins. content-type and content-length are ignored here, since they come from each body. |
defaultError | A schema for the body of the API's error responses (see Typed error bodies). |
statusErrors | Your own errors for error responses, by status, for every call (see Errors by status). |
plugins | Behavior every call goes through, outermost first (see Built-in plugins). |