sigildocs

(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

routeprocedure

A route consists of a method, pattern, and handler

route?procedure

Test if a value is a route struct.

route-methodprocedure

Get the method field of a route struct.

route-patternprocedure

Get the pattern field of a route struct.

route-handlerprocedure

Get the handler field of a route struct.

parse-patternprocedure

Parse a route pattern into segments Returns list of: string (literal), (:param name), (*splat name)

parse-segmentprocedure

Parse a single path segment

match-patternprocedure

Match a path against a parsed pattern Returns alist of params on match, #f on no match

Match path segments against pattern segments

make-routerprocedure

Create a router from a list of routes Returns a handler function: (request) -> response or #f

routerprocedure

Convenience macro-like function for creating routers Usage: (router (route 'GET "/" handler1) (route 'POST "/api" handler2))

path-paramprocedure

Get a path parameter from request Returns value or #f if not found

path-paramsprocedure

Get all path parameters from request

routesprocedure

Combine 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))