(sigil web routes)
(sigil web routes) - Path-based Request Routing
Provides routing functionality for web applications. Routes are matched in order; first match wins.
Example: (define app (router (route GET "/" home-handler) (route GET "/users/:id" user-handler) (route POST "/api/login" login-handler) (route ANY "/static/*path" static-handler)))
Exports
routeprocedureA route consists of a method, pattern, and handler
route?procedureTest if a value is a route struct.
route-methodprocedureGet the method field of a route struct.
route-patternprocedureGet the pattern field of a route struct.
route-handlerprocedureGet the handler field of a route struct.
parse-patternprocedureParse a route pattern into segments Returns list of: string (literal), (:param name), (*splat name)
parse-segmentprocedureParse a single path segment
match-patternprocedureMatch a path against a parsed pattern Returns alist of params on match, #f on no match
match-segmentsprocedureMatch path segments against pattern segments
make-routerprocedureCreate a router from a list of routes Returns a handler function: (request) -> response or #f
routerprocedureConvenience macro-like function for creating routers Usage: (router (route 'GET "/" handler1) (route 'POST "/api" handler2))
path-paramprocedureGet a path parameter from request Returns value or #f if not found
path-paramsprocedureGet all path parameters from request
routesprocedureCombine multiple handlers into a single handler.
Returns the first non-#f response. Use with the threading macro to build middleware chains:
(-> (routes api-routes page-routes static-handler)
(with-logging)
(with-not-found))