Client API
Fulgur's client is a thin wrapper around Eden Treaty, the official type-safe client from the Elysia ecosystem. Eden Treaty reads your Elysia server types at compile time and produces a fully typed HTTP client — no code generation step, no OpenAPI schema to maintain.
Setup
Export the App type from your entry point, then create a client:
// src/route.server.ts
const app = new Elysia().use(/* ... */);
export default app;
export type App = typeof app; // ← this is the type contract// src/lib/api.ts
import type { App } from "../route.server";
import { createClient } from "fulgur/client";
export const api = createClient<App>();import type is stripped at build time — server code never reaches the client bundle.
Making requests
// GET /api/hello
const { data, error } = await api.hello.get();
// POST /api/users with body
const { data } = await api.users.post({
name: "Alice",
});
// GET /api/users/:id
const { data } = await api.users({ id: 1 }).get();Type inference
Every response is fully typed based on what your Elysia routes return:
const { data } = await api.hello.get();
// ^? { message: string }
const { data } = await api.users.post({ name: "Alice" });
// ^? { created: string }TypeScript will catch invalid paths, wrong HTTP methods, and incorrect request bodies at compile time.
Error handling
Eden Treaty returns data and error separately:
const { data, error } = await api.hello.get();
if (error) {
console.error("Request failed:", error.status);
return;
}
console.log(data.message);How it works
createClient is a small factory built on top of Eden Treaty. It creates a proxy that:
- Maps property access to URL paths (
api.users.get()→GET /api/users) - Serializes request bodies and query parameters
- Deserializes JSON responses
- Infers all types from the
Appgeneric — the same Elysia type from your server
In the browser, requests go to the same origin. In development, the Vite dev proxy forwards /api requests to the backend.
For advanced Eden Treaty usage (custom headers, interceptors, $fetch), refer to the Eden Treaty docs.
