Core data-structure-driven routing.
The main functions to call are:
(resolve-endpoint routes {:path string})
(generate-path routes {:endpoint form, ...params})
The main protocols to extend are Routes and Pattern.
Core data-structure-driven routing. The main functions to call are: (resolve-endpoint routes {:path string}) (generate-path routes {:endpoint form, ...params}) The main protocols to extend are Routes and Pattern.
(make-handler routes)
(make-handler routes endpoint->handler)
Create a Ring handler (a function that takes a request and returns a response) from the given Routes that resolves the endpoint from the request's URI, maps the endpoint to a handler, and calls the handler with the request. Sets :route-params on the request the resolved endpoint map, sans :endpoint. Throws if no endpoint can be resolved.
Create a Ring handler (a function that takes a request and returns a response) from the given Routes that resolves the endpoint from the request's URI, maps the endpoint to a handler, and calls the handler with the request. Sets :route-params on the request the resolved endpoint map, sans :endpoint. Throws if no endpoint can be resolved.
Common protocol for treating both sequences and maps as pairs of items
Common protocol for treating both sequences and maps as pairs of items
(pairs this)
Iterate by pairs
Iterate by pairs
Left side of a Route (the other side is the result if this pattern matches). Consumers usually won't call these functions directly, but can use this protocol to implement custom patterns.
Left side of a Route (the other side is the result if this pattern matches). Consumers usually won't call these functions directly, but can use this protocol to implement custom patterns.
(generate-pattern-path this m)
Generate the string that would be matched by this pattern,
extracting parameters from m
if needed, or nil if there is a parameter
in the pattern that's not provided in m
.
Generate the string that would be matched by this pattern, extracting parameters from `m` if needed, or nil if there is a parameter in the pattern that's not provided in `m`.
(match-pattern this m)
If m
matches this pattern, update/remove the parts consumed
by the pattern and return the new m
; otherwise return nil.
If `m` matches this pattern, update/remove the parts consumed by the pattern and return the new `m`; otherwise return nil.
Right side of a Route, to be used when the corresponding left side, the Pattern, is matched. A Routes structure is recursively treated as [Pattern Route] tuples, where Route is either another Routes structure or an Endpoint, and Endpoint is anything that does not implement the Routes protocol.
Right side of a Route, to be used when the corresponding left side, the Pattern, is matched. A Routes structure is recursively treated as [Pattern Route] tuples, where Route is either another Routes structure or an Endpoint, and Endpoint is anything that does not implement the Routes protocol.
(generate-path this m)
Generate the path string that points to m
(based on its :endpoint and other parameters).
While this
is the full Routes structure, path generation works from the bottom up;
when recursing down into the Routes structure, the Pattern side is ignored until
a leaf endpoint matches the :endpoint in m
; only then are the Patterns rendered
to strings via generate-pattern-path, starting with the leaf-most Pattern.
Returns nil if no route in this
matches m
.
Generate the path string that points to `m` (based on its :endpoint and other parameters). While `this` is the full Routes structure, path generation works from the bottom up; when recursing down into the Routes structure, the Pattern side is ignored until a leaf endpoint matches the :endpoint in `m`; only then are the Patterns rendered to strings via generate-pattern-path, starting with the leaf-most Pattern. Returns nil if no route in `this` matches `m`.
(resolve-endpoint this m)
Iterate through the [pattern route] pairs in the Routes structure this
.
If pattern
matches m
(based on its :path and maybe other parameters),
AND route is an Endpoint, return m
with :endpoint set to route;
ELSE recurse into the matching Routes data structure.
If no pattern
matches the current m
, return nil.
Iterate through the [pattern route] pairs in the Routes structure `this`. If `pattern` matches `m` (based on its :path and maybe other parameters), AND route is an Endpoint, return `m` with :endpoint set to route; ELSE recurse into the matching Routes data structure. If no `pattern` matches the current `m`, return nil.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close