Skip to content

Route Modifiers

where(cParamName, cPattern)

Add regex constraint to route parameter.

@get("/users/:id", func { ... })
where("id", "[0-9]+")  # id must be numeric

Wildcard / Catch-All Segments

A * segment in a route pattern matches the remainder of the URL path:

# Named — capture via $bolt.param
@get("/files/*path", func { ... })      # /{path:.*}

# Anonymous — match only, no param
@get("/*", func { ... })                # /{_:.*}

Wildcards must be the last path segment.

whereAll(aConstraints)

Add multiple constraints at once.

@get("/posts/:year/:month", func { ... })
whereAll([
    ["year", "[0-9]{4}"],
    ["month", "[0-9]{2}"]
])

describe(cDescription)

Add description for OpenAPI docs.

@get("/users", func { ... })
describe("Get all users")

tag(cTag)

Add tag for OpenAPI docs (can be called multiple times).

@get("/users", func { ... })
tag("Users")
tag("Admin")

prefix(cPrefix) / endPrefix()

Group routes under a common prefix.

prefix("/api/v1")
    @get("/users", func { ... })     # /api/v1/users
    @get("/posts", func { ... })     # /api/v1/posts
endPrefix()

before(cMiddlewareName)

Add a before middleware to the last registered route.

@get("/api/data", func { ... })
before("authMiddleware")

after(cMiddlewareName)

Add an after middleware to the last registered route.

@get("/api/data", func { ... })
after("logMiddleware")

routeRateLimit(nMax, nWindow)

Add rate limiting to the last registered route.

@get("/api/data", func { ... })
routeRateLimit(100, 60)