Eden Installation

Start by installing Eden on your frontend:

bun add teasim @teasim/eden
TIP

Eden can't infer types correctly, without Teasim installed.

You can install Teasim as dev dependencies, as Teasim on client is only for infering types.

First, export your existing Teasim server type:

// server.ts
import { Teasim, t } from "teasim";

const app = new Teasim()
  .get("/", () => "Hi Teasim")
  .get("/id/:id", ({ params: { id } }) => id)
  .post("/mirror", ({ body }) => body, {
    body: t.Object({
      id: t.Number(),
      name: t.String(),
    }),
  })
  .listen(8080);

export type App = typeof app;

Then consume the Teasim API on client side:

// client.ts
import { edenTreaty } from '@teasim/eden'
import type { App } from './server'

const client = edenTreaty<App>('http://localhost:8080')

// response type: 'Hi Teasim'
client.index.get().then(console.log)

// response type: 1895
client.id.1895.get().then(console.log)

// response type: { id: 1895, name: 'Skadi' }
client.mirror.post({
    id: 1895,
    name: 'Skadi'
}).then(console.log)