1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as FetchHttpClient from "effect/http/FetchHttpClient";
5import * as HttpApiClient from "effect/http-api/HttpApiClient";
6import { BackendApi } from "./BackendApi.ts";
7import { env } from "./Env.ts";
8
9const backendClient = HttpApiClient.make(BackendApi, {
10 baseUrl: "http://localhost",
11}).pipe(
12 Effect.provide(
13 FetchHttpClient.layer.pipe(
14 Layer.provide(
15 Layer.succeed(FetchHttpClient.Fetch, ((input, init) =>
16 env.BACKEND.fetch(input, init)) as typeof globalThis.fetch),
17 ),
18 ),
19 ),
20);
21
22export class BackendClient extends Context.Service<
23 BackendClient,
24 Effect.Success<typeof backendClient>
25>()("BackendClient") {
26 static Default = Layer.effect(BackendClient, backendClient);
27}