ronda.routing
active-routed-middleware
added in 0.2.0
(active-routed-middleware handler middleware-key wrap-fn & args)
Generate a handler that applies the middleware represented by `wrap-fn`
unless it is explicitly disabled for the currently routed endpoint.
This has to be used below `ronda.routing.middleware/wrap-routing`.
compile-endpoints
(compile-endpoints handlers)
Create a Ring handler that intercepts all requests that had an endpoint ID
determined by `wrap-routing` and routes them to the matching handler in the
given handlers map. If no match is found, `nil` is returned.
conditional-middleware
(conditional-middleware handler p? wrap-fn)
Apply the given middleware only if the request matches the given predicate.
descriptor
(descriptor request)
Get the descriptor that caused the request to be routed.
disable-middlewares
(disable-middlewares descriptor route-id ks & more)
Disable the given middlewares for the endpoint identified by the given
route ID/middleware key pairs.
enable-middlewares
(enable-middlewares descriptor route-id ks & more)
Enable the given middlewares for the endpoint identified by the given
route ID/middleware key pairs.
endpoint
(endpoint request)
Get the endpoint data the request should be routed to.
endpoint-middleware
(endpoint-middleware handler endpoints wrap-fn)
Like `conditional-middleware`, applying the given middleware only if the
request is being routed to one of the given endpoints. (A single
non-sequential endpoint ID may be given instead of a seq of multiple.)
href
(href request route-id)
(href request route-id values)
Generate path + query string for the given route based on the RouteDescriptor
stored in the given request.
match
(match request path)
(match request request-method path)
Parse the given path and create a map of `:id`, `:route-params`,
`:query-params` and `:params` based on the RouteDescriptor stored
in the given request.
path
(path request route-id)
(path request route-id values)
Generate the path component for the given route based on the
RouteDescriptor stored in the given request.
prefix
(prefix descriptor prefix)
Create a new RouteDescriptor representing the routes of the given one
prefixed by a bidi-style route, e.g.
(prefix d "/a")
(prefix d ["/" :locale])
(prefix d ["/" [#"de|fr|us" :locale]])
routed-middleware
(routed-middleware handler middleware-key wrap-fn & args)
Generate a handler that applies the middleware represented by `wrap-fn` only
if it is explicitly enabled for the currently routed endpoint.
This has to be used below `ronda.routing.middleware/wrap-routing`.
routes
(routes _)
Return a map associating route IDs with a map of `:path` (the full
path to the endpoint using bidi's route format) and `:methods`
(the set of request methods applicable for the endpoint), as well as
all the additional `:meta` data set using `update-metadata`.
routing-data
(routing-data request)
Get the routing data for the given request
wrap-endpoint
(wrap-endpoint default-handler endpoint-id handler)
Create a Ring handler that intercepts all requests that had the given
endpoint ID determined by `wrap-routing`, delegating them to the given
handler.
wrap-endpoints
(wrap-endpoints default-handler handlers)
Create a Ring handler that intercepts all requests that had an endpoint ID
determined by `wrap-routing` and routes them to the matching handler in
the given handlers map. If no match is found, the request is passed to the
given default handler.
wrap-routing
(wrap-routing handler descriptor & [{:keys [response?], :or {response? false}}])
Wrap the given Ring handler with middleware-based routing using the given
RouteDescriptor. If a route can be found for a request the descriptor,
route params and endpoint ID are injected into the request map which is then
passed to the original handler. If no route can be found, the request is passed
to the handler unaltered.
If `:response?` is set to `true` in the optional options map, routing
metadata and descriptor is attached to the response, as well.