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`.

assoc-metadata

added in 0.2.0

(assoc-metadata descriptor route-id k v)
Assoc a key/value pair into the given routes metadata.

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.

conditional-transform

(conditional-transform handler p? f)
Apply the given transformation function to the request, only if it 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.)

endpoint-transform

(endpoint-transform handler endpoints f)
Like `conditional-transform`, applying the given function to requests
that are 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.

merge-metadata

added in 0.2.0

(merge-metadata descriptor route-id m)
Merge the given map into the given routes metadata.

meta-middleware

added in 0.2.1

(meta-middleware handler middleware-key wrap-fn)
If routing metadata is available, builds a (memoized) handler using
`(wrap-fn handler route-id metadata)` and routes the request to it.

The middleware data is expected at `[:meta :middlewares k]` of the routing
metadata attached by `wrap-routing` and the middleware itself is supposed to
be activated using `enable-middlewares`. Note that even `nil` metadata is
allowed an will be passed to `wrap-fn`.

If `wrap-fn` returns `nil`, no middleware will be applied.

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

update-metadata

(update-metadata _ route-id f)
Return a new RouteDescriptor that applies the given function to the given
route's metadata.

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.