Effect CommunityEC
Effect Community13mo ago
8 replies
ciokan

IS there a way to create a `HttpApiClient` without relying on server code?

This example defined both the server and the client in the same file but can I create a client in a separate project (based on openapi defs or something) without having to import server code/types?

import {
  HttpApi,
  HttpApiClient,
  HttpApiEndpoint,
  HttpApiGroup
} from "@effect/platform"
import { Effect, Schema } from "effect"

const api = HttpApi.make("api").add(
  // Mark the group as top-level
  HttpApiGroup.make("group", { topLevel: true }).add(
    HttpApiEndpoint.get("get", "/").addSuccess(Schema.String)
  )
)

const program = Effect.gen(function* () {
  const client = yield* HttpApiClient.make(api, {
    baseUrl: "http://localhost:3000"
  })
  // The `get` method is not nested under the "group" name
  const user = yield* client.get()
  console.log(user)
})
Was this page helpful?