Clients
Derive a client
Make a client from another, with a different base URL or one more header.
This page shows how to make a second client from a first one, for the same client with a different base URL, such as a second API version, or with one more header.
Spread the first client's config
Spread the first class's config into a second class. The second class
keeps the plugins, defaultError and statusErrors, so its client has the
same type:
import * as from "effect/Schema";
import { } from "@monarcode/effetch";
import { } from "@monarcode/effetch/plugins";
export class extends .<>()("Api", {
: "https://api.example.com/v1",
: .({ : . }),
: [()],
}) {}
export class extends .<>()("ApiV2", {
....,
: "https://api.example.com/v2",
}) {}Keep the first client's headers
When you set headers, Api.config.headers is replaced, not merged. To
keep the first client's headers, spread them too, as in
headers: { ...Api.config.headers, "x-client": "web" }.
What's next
- Client configuration: look up the options you can override.
- Structure an app: organize an app that talks to several backends.