Define a Route
Bind methods to HTTP routes with @HttpService and @HttpRoute, and control the response.
Routes live on service classes: @HttpService() marks the class as an HTTP surface, @HttpRoute(method, path) binds each method. REST endpoints are the right tool for public and third-party-facing APIs; for your own frontend or worker-to-worker calls, prefer RPC.
A basic route
Register the class in your worker's services array in settings.ts — a class that isn't listed doesn't exist:
Handlers can be async and routes can use :param segments (see Read Request Parameters).
Multiple methods, any method
@HttpRoute takes a single method, an array, or 'ALL':
Route matching order
Routes bind in registration order and the first match wins: within a service,
methods top to bottom; across services, in services-array order. A
parameterized segment matches anything, so GET /:name also matches /notes
— if both exist, the service with the static route must be registered first:
Response handling
You control how much ceremony a response gets:
- Return a
Responsefor full control: status, headers, streaming. - Return a plain object (or array) and Base wraps it in
Response.json(...). - Return a string and it becomes a plain-text response body.
- Return nothing and Base sends an empty
200 OK.
Errors
Throw an HttpErrors factory error anywhere in a handler and Base converts it to the matching HTTP response with a structured error body:
The factories cover the standard range: badRequest, unauthorized, forbidden, notFound, methodNotAllowed, conflict, unprocessableEntity, internalServerError, serviceUnavailable, and more. To return an error response without throwing, wrap it: HttpResponses.fromError(HttpErrors.forbidden({ ... })) (from @system-inc/base-foundation/http/HttpResponses).