HttpApi module. Every endpoint is fully type-safe from request parsing through to the response schema — no runtime casting required.
Starting the server
Start the HTTP server
Run the The server reads the
http script from the repository root (or from inside backend/).COFFEE_HTTP_PORT environment variable and falls back to port 3000 when it is not set.bun run dev also starts the HTTP server alongside the frontend Vite dev server through Turborepo. Use bun run http when you only need the backend.Base URL
COFFEE_HTTP_PORT to any available port before starting if 3000 is already taken:
API groups
Effect’sHttpApi model organises endpoints into named groups. The coffee shop API defines three:
HealthApi
A single top-level health-check endpoint with no prefix. Used by load balancers and readiness probes.
MenuApi
Menu retrieval endpoints rooted at
/menu.OrdersApi
Full order lifecycle — create, list, fetch, and all barista status transitions — rooted at
/orders.CoffeeHttpApi declaration and served as one router:
Endpoints
HealthApi
| Method | Path | Description |
|---|---|---|
GET | /health | Returns {"status":"ok"} when the server is running. |
MenuApi
| Method | Path | Description |
|---|---|---|
GET | /menu | Returns the full list of drinks available for ordering. |
OrdersApi
All order endpoints share the/orders prefix.
| Method | Path | Description |
|---|---|---|
POST | /orders | Place a new coffee order. |
GET | /orders | List orders, optionally filtered by status. |
GET | /orders/:orderId | Fetch a single order by ID. |
POST | /orders/:orderId/start-brewing | Transition an order from pending to brewing. |
POST | /orders/:orderId/mark-ready | Transition an order from brewing to ready. |
POST | /orders/:orderId/pick-up | Transition an order from ready to picked-up. |
POST | /orders/:orderId/cancel | Cancel a pending or brewing order. |
Place an order — POST /orders
The request body follows the PlaceOrderRequest schema. size defaults to medium when omitted.
List orders — GET /orders
An optional status query parameter filters by order status.
Get one order — GET /orders/:orderId
Barista status transitions
CoffeeOrder object. Requests that violate the state machine (e.g., marking a cancelled order as ready) return an InvalidOrderStatusTransitionError.
OpenAPI specification
The server exposes a machine-readable OpenAPI JSON document at:HttpApiBuilder.layer call inside api.ts:
http://localhost:3000/openapi.json.
How Effect HttpApi generates type-safe handlers
Each API group is defined as a class that extendsHttpApiGroup.make. Endpoints declare their method, path, request shape, success schema, and possible error schemas in one place:
HttpApiBuilder.group. The compiler enforces that every declared endpoint has exactly one handler and that the handler returns the correct type: