End-to-End Type Safety - ElysiaJS | ElysiaJS

ID: 2131https://elysiajs.com/eden/overview.html
Source

End‑to‑End Type Safety

Imagine you have a toy train set.
Each piece of the train track has to fit perfectly with the next one, like puzzle pieces.
End‑to‑end type safety is like making sure all the pieces of the track match up correctly so the train doesn’t fall off or get stuck.
For a framework to have end‑to‑end type safety means you can connect client and server in a type‑safe manner.

Elysia provides end‑to‑end type safety without code generation out of the box with an RPC‑like connector, Eden.

▶︎ Interactive Playground

Eden Treaty demo

Other frameworks that support e2e type safety:

  • tRPC
  • Remix
  • SvelteKit
  • Nuxt
  • TS‑Rest

Elysia lets you change the type on the server and it will be instantly reflected on the client, helping with auto‑completion and type‑enforcement.

Eden

Eden is an RPC‑like client to connect Elysia with end‑to‑end type safety using only TypeScript’s type inference instead of code generation.
It weighs less than 2 KB.

Eden consists of two modules:

  1. Eden Treaty (recommended) – an improved RPC version of Eden Treaty
  2. Eden Fetch – a fetch‑like client with type safety

Below is an overview, use‑case and comparison for each module.

Eden Treaty (Recommended)

Eden Treaty is an object‑like representation of an Elysia server providing end‑to‑end type safety and a significantly improved developer experience.
With Eden Treaty we can interact with an Elysia server with full‑type support and auto‑completion, error handling with type narrowing, and create type‑safe unit tests.

Example usage of Eden Treaty

import { treaty } from '@elysiajs/eden'
import type { App } from './server'

const app = treaty<App>('localhost:3000')

// Call [GET] at '/'
const { data } = await app.get()

// Call [PUT] at '/nendoroid/:id'
const { data: nendoroid, error } = await app.nendoroid.put({
  id: 1895,
  name: 'Skadi',
  from: 'Arknights'
})

treaty automatically infers the types of the routes, query parameters, body, and response.
It also gives you compile‑time error checking and auto‑completion for all server routes.

Eden Fetch

A fetch‑like alternative to Eden Treaty for developers that prefer fetch syntax.

import { edenFetch } from '@elysiajs/eden'
import type { App } from './server'

const fetch = edenFetch<App>('http://localhost:3000')

const { data } = await fetch('/name/:name', {
  method: 'POST',
  params: { name: 'Saori' },
  body: {
    branch: 'Arius',
    type: 'Striker'
  }
})

Note
Unlike Eden Treaty, Eden Fetch doesn’t provide Web Socket implementation for an Elysia server.


Last updated: 2025‑11‑23

Edit this page on GitHub: https://github.com/elysiajs/documentation/edit/main/docs/eden/overview.md