Routing
Register specific routes before wildcards
Routes are considered in registration order. An exact path matches itself. A path ending in * matches its prefix. Put specific paths before broad prefixes; this is not a parameterized router with {id} captures.
import http
let define_routes = fn () -> i64 {
http "127.0.0.1" 8080 {
GET "/api/health" -> fn (request:Http:Request*, response:Http:Response*) -> void {
response.text(200, "ok")
}
GET "/api/*" -> fn (request:Http:Request*, response:Http:Response*) -> void {
response.text(404, "unknown API endpoint")
}
}
return 0
}Method handling
- Method comparisons are case insensitive.
- A
GETroute also handlesHEAD; the writer omits the response body while preserving its declared length. - A programmatic
ANYroute accepts any method and still follows registration order. - No match produces
404, unlessServer:on_not_foundsupplies another handler.
Check registration and callback lifetime
Server:route copies the method and path but borrows the callback. Check its return value; allocation failure means the route was not registered. Keep callback code available for the entire serving lifetime.