stch.routing documentation
DSL for routing Ring requests.
->Router
(->Router req req-path req-method resp)
Positional factory function for class stch.routing.Router.
-body
(-body this)
Returns the request body.
-domain
(-domain this d f)
If the server-name key matches d, call f.
-guard
(-guard this check)
(-guard this check msg)
If check is falsey return immediately with a
forbidden error, and optional message.
-index
(-index this f)
If there are no path segments, call f.
-lookup-param
(-lookup-param this param)
Returns the specified param.
-method
(-method this meth f)
If the request-method key matches meth,
call f.
-not-traversed
(-not-traversed this f)
If the current path level has not been traversed
previously, call f.
-param
(-param this parser f)
If the next path segment can be matched according
to regex pattern, use the corresponding parser and
pass the result to f.
-params
(-params this)
Returns the params map (if present).
-path
(-path this segment f)
If the next path segment matches segment,
call f.
-pred
(-pred this p f)
If (p path-segment) returns truthy then,
call f passing the result of the above.
-request
(-request this)
Returns the request map.
-scheme
(-scheme this s f)
If the scheme key matches s, call f.
-static
(-static this segments opts)
If the next path segment matches a value in the
segments set and the request method is get,
return a file response corresponding to the
requested file.
-terminate
(-terminate this resp)
Terminate and respond with resp immediately.
-truncate
(-truncate this f)
Truncate any remaining path segments and call f.
If a response is not created inside truncate
(for example, by means of a call to method),
revert the zipper to it's previous state.
-url
(-url this)
Returns the request url.
-zipper
(-zipper this)
Inspect the current state of the zipper. Useful
for debugging.
IDispatch
Dispatch a request.
IRequest
Common request accessors.
Request
Request type annotation.
RequestMethods
Request methods type annotation.
body
macro
(body)
Returns the request body (if present).
Use with route or route'.
defroute
macro
(defroute name & body)
Define a routing Ring handler.
defroute'
macro
(defroute' name & body)
Define a routing Ring handler.
Use with routes.
domain
macro
(domain d & body)
If the server-name key matches d, evaluate body.
Use with route or route'.
guard
macro
(guard check)
(guard check msg)
If check is falsey return immediately with a
forbidden error, and optional message.
Use with route or route'.
index
macro
(index & body)
If there are no path segments, evaluate body.
Use with route or route'.
init-router
(init-router req)
Inputs: [req :- Request]
Returns: Router
Initialize the router.
lookup-param
macro
(lookup-param param)
Returns the specified param.
Use with route or route'.
map->Router
(map->Router m3921)
Factory function for class Router, taking a map of keywords to field values, but not 400x slower than ->x like the clojure.core version
method
macro
(method method & body)
If the request-method key matches meth,
evaluate body.
Use with route or route'.
not-traversed
macro
(not-traversed & body)
If the current path level has not been traversed
previously, evaluate body.
Use with route or route'.
param
macro
(param parser bindings & body)
If the next path segment can be matched according
to regex pattern, use the corresponding parser and
evaluate body with bindings set to parsed value.
Use with route or route'.
params
macro
(params)
Returns the params map (if present).
Use with route or route'.
path
macro
(path segment & body)
If the next path segment matches segment,
evaluate body.
Use with route or route'.
pred
macro
(pred p bindings & body)
If (p path-segment) returns truthy then,
evaluate body with bindings set to the value
returned by (p path-segment).
Use with route or route'.
request
macro
(request)
Returns the request map.
Use with route or route'.
route
macro
(route & body)
Entrypoint for routing. Returns a Ring handler.
Calls respond.
route'
macro
(route' & body)
Alternate entrypoint for routing. Returns a Ring
handler. Does not call respond.
Use with routes.
routes
(routes & handlers)
Inputs: [& handlers :- [(Fn Any [Request])]]
Returns: (Fn Any [Request])
Compose multiple routes. Returns a Ring handler.
Calls respond.
scheme
macro
(scheme s & body)
If the scheme key matches s, evaluate body.
Use with route or route'.
static
macro
(static segments opts)
If the next path segment matches a value in the
segments set and the request method is get,
return a file response corresponding to the
requested file.
Use with route or route'.
strict-map->Router
(strict-map->Router m3922 & [drop-extra-keys?__1737__auto__])
Factory function for class Router, taking a map of keywords to field values. All keys are required, and no extra keys are allowed. Even faster than map->
terminate
macro
(terminate resp)
Terminate and respond with resp immediately.
Use with route or route'.
truncate
macro
(truncate & body)
Truncate any remaining path segments and evaluate body.
If a response is not created inside truncate
(for example, by means of a call to method),
revert the zipper to it's previous state.
Use with route or route'.
url
macro
(url)
Returns the request url.
Use with route or route'.
zipper
macro
(zipper)
Inspect the current state of the zipper. Useful
for debugging.
Use with route or route'.