Skip to main content

Routing

Prism’s router matches incoming requests to handlers using URL patterns. It supports path parameters, wildcards, route groups, and nested prefixes.

Basic Routes

Register routes with the HTTP method and a URL pattern:
Basic Routes
You can also use the generic route method:

Path Parameters

Capture dynamic URL segments with :paramName:
Path Parameters
Parameters are always strings. Parse them in your handler: Int(request.parameters["id"]!) for integers.

Wildcards

The * wildcard matches any remaining path:
Wildcard Routes

Route Groups

Group related routes under a shared prefix. Groups can have their own middleware:
Route Groups
This produces:
  • GET /api/status — no auth required
  • GET /api/admin/users — auth required
  • POST /api/admin/users — auth required
  • DELETE /api/admin/users/:id — auth required

REST Resource Pattern

A common pattern for building RESTful APIs:
REST Resource

Route Priority

Routes are matched in registration order. The first match wins:
Register specific routes before parameterized ones. /users/me should come before /users/:id, otherwise :id will capture “me” as a parameter.

Query Parameters

Query parameters are automatically parsed from the URL:
Query Parameters

Request

Learn how to extract data from incoming requests.

Middleware

Add cross-cutting concerns to route groups.