Liking cljdoc? Tell your friends :D

calfpath.route

Data driven routes functionality in Calfpath.

Data driven routes functionality in Calfpath.
raw docstring

*routes*clj/s

source

assoc-kv-middlewareclj/s

(assoc-kv-middleware route main-key-finder assoc-map)

Given a route, if the route contains the main key then ensure that it also has the associated key/value pairs.

Given a route, if the route contains the main key then ensure that it also has the associated key/value pairs.
sourceraw docstring

assoc-route-to-request-middlewareclj/s

(assoc-route-to-request-middleware route)
(assoc-route-to-request-middleware route route-key)

Given a route, decorate the handler such that the request has the route under specified key (:route by default) at runtime.

Given a route, decorate the handler such that the request has the route under specified key (`:route` by default)
at runtime.
sourceraw docstring

compile-routesclj/s

(compile-routes routes)
(compile-routes routes
                {:keys [easy? tidy? tidy-threshold uri? uri-key fallback-400?
                        show-uris-400? full-uri-key uri-prefix-400 params-key
                        method? method-key fallback-405? trailing-slash
                        lift-uri? ring-handler? ring-handler-key]
                 :or {tidy-threshold 1
                      full-uri-key :full-uri
                      method? true
                      trailing-slash false
                      tidy? true
                      method-key :method
                      uri? true
                      params-key :path-params
                      fallback-405? true
                      lift-uri? true
                      show-uris-400? true
                      fallback-400? true
                      uri-key :uri
                      easy? true}
                 :as options})

Given a collection of routes, supplement them with required entries and finally return a routes collection.

Options

KwargTypeDescription
:easy?booleanallow easy defnition of routes that translate into regular routes
:tidy?booleanoptimize URI routes by automatically reorganizing routes
:tidy-thresholdintegersimilar routes more than this number will be grouped together
:uri?booleantrue if URI templates should be converted to matchers
:uri-keynon-nilthe key to be used to look up the URI template in a route
:params-keynon-nilthe key to put URI params under in the request map
:trailing-slashkeywordTrailing-slash action to perform on URIs - :add or :remove - nil (default) has no effect
:fallback-400?booleanwhether to add a fallback route to respond with HTTP status 400 for unmatched URIs
:show-uris-400?booleanwhether to add URI templates in the HTTP 400 response (see :fallback-400?)
:full-uri-keynon-nilthe key to be used to populate full-uri for reporting HTTP 400 (see :show-uris-400?)
:uri-prefix-400string?the URI prefix to use when showing URI templates in HTTP 400 (see :show-uris-400?)
:method?booleantrue if HTTP methods should be converted to matchers
:method-keynon-nilthe key to be used to look up the method key/set in a route
:fallback-405?booleanwhether to add a fallback route to respond with HTTP status 405 for unmatched methods
:lift-uri?booleanwhether lift URI attributes from mixed routes and move the rest into nested routes

See: dispatch, make-dispatcher (Clojure/JVM only), make-index

Given a collection of routes, supplement them with required entries and finally return a routes collection.

### Options

| Kwarg           | Type  | Description                                                                            |
|-----------------|-------|----------------------------------------------------------------------------------------|
|`:easy?`         |boolean|allow easy defnition of routes that translate into regular routes                       |
|`:tidy?`         |boolean|optimize URI routes by automatically reorganizing routes                                |
|`:tidy-threshold`|integer|similar routes more than this number will be grouped together                           |
|`:uri?`          |boolean|true if URI templates should be converted to matchers                                   |
|`:uri-key`       |non-nil|the key to be used to look up the URI template in a route                               |
|`:params-key`    |non-nil|the key to put URI params under in the request map                                      |
|`:trailing-slash`|keyword|Trailing-slash action to perform on URIs - :add or :remove - nil (default) has no effect|
|`:fallback-400?` |boolean|whether to add a fallback route to respond with HTTP status 400 for unmatched URIs      |
|`:show-uris-400?`|boolean|whether to add URI templates in the HTTP 400 response (see :fallback-400?)              |
|`:full-uri-key`  |non-nil|the key to be used to populate full-uri for reporting HTTP 400 (see :show-uris-400?)    |
|`:uri-prefix-400`|string?|the URI prefix to use when showing URI templates in HTTP 400 (see :show-uris-400?)      |
|`:method?`       |boolean|true if HTTP methods should be converted to matchers                                    |
|`:method-key`    |non-nil|the key to be used to look up the method key/set in a route                             |
|`:fallback-405?` |boolean|whether to add a fallback route to respond with HTTP status 405 for unmatched methods   |
|`:lift-uri?`     |boolean|whether lift URI attributes from mixed routes and move the rest into nested routes      |

See: [[dispatch]], [[make-dispatcher]] (Clojure/JVM only), [[make-index]]
sourceraw docstring

conj-fallback-400clj/s

(conj-fallback-400 routes)
(conj-fallback-400 routes {:keys [show-uris? uri-finder uri-prefix] :as opts})

Given a route vector append a matcher that always matches, and a handler that returns HTTP 400 response.

Given a route vector append a matcher that always matches, and a handler that returns HTTP 400 response.
sourceraw docstring

conj-fallback-405clj/s

(conj-fallback-405 routes {:keys [allowed-methods method-finder] :as opts})

Given a route vector append a matcher that always matches, and a handler that returns HTTP 405 response.

Given a route vector append a matcher that always matches, and a handler that returns HTTP 405 response.
sourceraw docstring

conj-fallback-matchclj/s

(conj-fallback-match routes handler)

Given a route vector append a matcher that always matches with a corresponding specified handler.

Given a route vector append a matcher that always matches with a corresponding specified handler.
sourceraw docstring

dispatchclj/s

(dispatch routes request)
(dispatch routes request f)
(dispatch routes request respond raise)

Given a vector of routes, recursively walk the routes evaluating the specified Ring request with each matcher. Invoke corresponding handler on successful match. Synopsis: 0. A route is a map {:matcher (fn [request]) -> request? ; :matcher is a required key :nested vector of child routes ; either :handler or :nested key must be present :handler Ring handler for route}

  1. A matcher is (fn [request]) that returns a potentially-updated request on successful match, nil otherwise.
  2. Handler is a Ring handler (fn [request] [request respond raise]) that responds to a Ring request.

See: compile-routes, make-dispatcher (Clojure/JVM only)

Given a vector of routes, recursively walk the routes evaluating the specified Ring request with each matcher.
Invoke corresponding handler on successful match.
Synopsis:
0. A route is a map {:matcher `(fn [request]) -> request?` ; :matcher is a required key
                     :nested  vector of child routes       ; either :handler or :nested key must be present
                     :handler Ring handler for route}
1. A matcher is (fn [request]) that returns a potentially-updated request on successful match, nil otherwise.
2. Handler is a Ring handler (fn [request] [request respond raise]) that responds to a Ring request.

See: [[compile-routes]], [[make-dispatcher]] (Clojure/JVM only)
sourceraw docstring

easy-routesclj/s

(easy-routes routes uri-key method-key)

Allow easy, recursively applied, route definition as in the following examples:

DefinitionTranslated into
{"/docs/:id/info" [...]}{:uri "/docs/:id/info" :nested [...]}
{"/docs/:id/info" (fn [req])}{:uri "/docs/:id/info" :handler (fn [req])}
{:delete (fn [request])}{:method :delete :handler (fn [request])}
{["/docs/:id" :get] (fn [req])}{:uri "/docs/:id" :method :get :handler (fn [req])}
Allow easy, recursively applied, route definition as in the following examples:

| Definition                         | Translated into                                       |
|------------------------------------|-------------------------------------------------------|
|`{"/docs/:id/info" [...]}`        |`{:uri "/docs/:id/info" :nested [...]}`              |
|`{"/docs/:id/info" (fn [req])}`   |`{:uri "/docs/:id/info" :handler (fn [req])}`        |
|`{:delete (fn [request])}`          |`{:method :delete :handler (fn [request])}`            |
|`{["/docs/:id" :get] (fn [req])}` |`{:uri "/docs/:id" :method :get :handler (fn [req])}`|
sourceraw docstring

ensure-matchexclj/s

(ensure-matchex route matchex)

Given a route not containing the :matchex key, assoc specified matchex into the route. If the route already contains :matchex then leave it intact.

Given a route not containing the `:matchex` key, assoc specified matchex into the route. If the route already
contains `:matchex` then leave it intact.
sourceraw docstring

lift-key-middlewareclj/s

(lift-key-middleware route lift-keys conflict-keys)

Given a route, lift keys and one or more conflict keys, if the route contains both any of the lift-keys and any of the conflict-keys then extract the lift keys such that all other attributes are moved into a nested route.

Given a route, lift keys and one or more conflict keys, if the route contains both any of the lift-keys and any
of the conflict-keys then extract the lift keys such that all other attributes are moved into a nested route.
sourceraw docstring

make-dispatcherclj

(make-dispatcher routes)
(make-dispatcher routes
                 {:keys [uri-key method-key]
                  :or {uri-key :uri method-key :method}
                  :as options})

Given a collection of routes return a Ring handler function that matches specified request and invokes corresponding route handler on successful match, returns nil otherwise. Synopsis: 0. A route is a map {:matcher (fn [request]) -> request? ; :matcher is a required key :matchex (fn [request-sym]) -> matcher ; optional (enabled by default) :nested routes-vector ; either :handler or :nested key must be present :handler Ring handler}

  1. A matcher is (fn [request]) that returns a potentially-updated request on successful match, nil otherwise.
  2. A matchex is (fn [request-sym]) that returns expression to eval instead of calling matcher. The matchex is used only when :matcher is also present. Expr should return a value similar to matcher.
  3. A matchex is for optimization only, which may be disabled by setting a false or nil value for the :matchex key.
  4. Handler is a Ring handler (fn [request] [request respond raise]) that responds to a Ring request.

See: compile-routes, dispatch

Given a collection of routes return a Ring handler function that matches specified request and invokes
corresponding route handler on successful match, returns nil otherwise.
Synopsis:
0. A route is a map {:matcher `(fn [request]) -> request?`     ; :matcher is a required key
                     :matchex `(fn [request-sym]) -> matcher`  ; optional (enabled by default)
                     :nested  routes-vector                    ; either :handler or :nested key must be present
                     :handler Ring handler}
1. A matcher is (fn [request]) that returns a potentially-updated request on successful match, nil otherwise.
2. A matchex is (fn [request-sym]) that returns expression to eval instead of calling matcher. The matchex is used
   only when :matcher is also present. Expr should return a value similar to matcher.
3. A matchex is for optimization only, which may be disabled by setting a false or nil value for the :matchex key.
4. Handler is a Ring handler (fn [request] [request respond raise]) that responds to a Ring request.

See: [[compile-routes]], [[dispatch]]
sourceraw docstring

make-ensurerclj/s

(make-ensurer k f)

Given a key and factory fn (accepts route and other args, returns new route), create a route updater fn that applies f to the route only when it does not contain the key.

Given a key and factory fn (accepts route and other args, returns new route), create a route updater fn that applies
f to the route only when it does not contain the key.
sourceraw docstring

make-indexclj/s

(make-index routes)
(make-index routes options)

Given a collection of routes, index them returning a map {:id route-template}.

Options:

KwargDescription
:index-keyThe index key in given routes, default :id
:uri-keyThe URI key in given routes, default :uri
:method-keyHTTP method key in given routes, default :method

See: compile-routes, template->request

Given a collection of routes, index them returning a map {:id route-template}.

Options:

| Kwarg       | Description                                      |
|-------------|--------------------------------------------------|
|`:index-key` |The index key in given routes, default `:id`      |
|`:uri-key`   |The URI key in given routes, default `:uri`       |
|`:method-key`|HTTP method key in given routes, default `:method`|

See: [[compile-routes]], [[template->request]]
sourceraw docstring

make-method-matcherclj/s

(make-method-matcher route method-finder)

Given a route not containing the :matcher key and containing HTTP-method keyword (or keyword set) as value (found by method-finder), create a method matcher and add it under the :matcher key. If the route already contains the :matcher key or if it does not contain HTTP-method keyword/set then the route is left intact. When adding matcher also add matchex unless the :matchex key already exists.

Given a route not containing the `:matcher` key and containing HTTP-method keyword (or keyword set) as value
(found by method-finder), create a method matcher and add it under the `:matcher` key. If the route already
contains the `:matcher` key or if it does not contain HTTP-method keyword/set then the route is left intact. When
adding matcher also add matchex unless the `:matchex` key already exists.
sourceraw docstring

make-updaterclj/s

(make-updater k f)

Given a key and updater fn (accepts route and other args, returns new route), create a route updater fn that applies f to the route only when it contains the key.

Given a key and updater fn (accepts route and other args, returns new route), create a route updater fn that applies
f to the route only when it contains the key.
sourceraw docstring

make-uri-matcherclj/s

(make-uri-matcher route uri-finder params-key)

Given a route not containing the :matcher key and containing URI-pattern string as value (found by uri-finder), create a URI matcher and add it under the :matcher key. If the route already contains the :matcher key or if it does not contain URI-pattern then the route is left intact. When adding matcher also add matchex unless the :matchex key already exists.

Given a route not containing the `:matcher` key and containing URI-pattern string as value (found by uri-finder),
create a URI matcher and add it under the `:matcher` key. If the route already contains the `:matcher` key or if it
does not contain URI-pattern then the route is left intact. When adding matcher also add matchex unless the
`:matchex` key already exists.
sourceraw docstring

prewalk-routesclj/s

(prewalk-routes routes parent-route f & args)

Given a bunch of routes, update every route (recursively) with f, which receives parent route as second arg.

Given a bunch of routes, update every route (recursively) with f, which receives parent route as second arg.
sourceraw docstring

realize-uriclj/s

(realize-uri uri-template
             {:keys [uri-params uri-prefix uri-suffix] :as options})

Given a vector of the form ['/users' :user-id '/profile/' :profile '/'] fill in the param values returning a URI.

See: template->request

Given a vector of the form ['/users' :user-id '/profile/' :profile '/'] fill in the param values returning a URI.

See: [[template->request]]
sourceraw docstring

routes->wildcard-tidyclj/s

(routes->wildcard-tidy routes)
(routes->wildcard-tidy routes
                       {:keys [tidy-threshold uri-key]
                        :or {tidy-threshold 1 uri-key :uri}
                        :as options})

Given a bunch of routes, segment them by prefix URI-tokens into a branched structure for faster match.

Given a bunch of routes, segment them by prefix URI-tokens into a branched structure for faster match.
sourceraw docstring

template->requestclj/s

(template->request request-template)
(template->request request-template
                   {:keys [uri-params uri-prefix uri-suffix] :as options})

Given a request template, realize the attributes to create a minimal Ring request. A request template may be found from a reverse index built using make-index.

Options:

KwargDescription
:uri-paramsmap of URI param values, e.g. {:lid 5 :rid 18}
:uri-prefixURI prefix string, e.g. "https://myapp.com/"
:uri-suffixURI suffix string, e.g. "?q=beer&country=in"

See: make-index

Given a request template, realize the attributes to create a minimal Ring request.
A request template may be found from a reverse index built using [[make-index]].

Options:

| Kwarg       | Description                                    |
|-------------|------------------------------------------------|
|`:uri-params`|map of URI param values, e.g. `{:lid 5 :rid 18}`|
|`:uri-prefix`|URI prefix string, e.g. `"https://myapp.com/"`|
|`:uri-suffix`|URI suffix string, e.g. `"?q=beer&country=in"`|

See: [[make-index]]
sourceraw docstring

trailing-slash-middlewareclj/s

(trailing-slash-middleware route uri-key action)

Given a route, URI key and action (keyword :add or :remove) edit the URI to have or not have a trailing slash if the route has a URI pattern. Leave the route unchanged if it has no URI pattern.

Given a route, URI key and action (keyword `:add` or `:remove`) edit the URI to have or not have a trailing slash
if the route has a URI pattern. Leave the route unchanged if it has no URI pattern.
sourceraw docstring

update-each-routeclj/s

(update-each-route routes f & args)

Given a bunch of routes, update every route (recursively) with f.

Given a bunch of routes, update every route (recursively) with f.
sourceraw docstring

update-fallback-400clj/s

(update-fallback-400 routes)
(update-fallback-400 routes uri-finder opts)

Update routes by appending a fallback HTTP-400 route only when all routes have :uri key.

Update routes by appending a fallback HTTP-400 route only when all routes have :uri key.
sourceraw docstring

update-fallback-405clj/s

(update-fallback-405 routes method-finder)
(update-fallback-405 routes method-finder opts)

Update routes by appending a fallback HTTP-405 route when all routes have :method key.

Update routes by appending a fallback HTTP-405 route when all routes have :method key.
sourceraw docstring

update-in-each-routeclj/s

(update-in-each-route routes reference-key f)

Given a bunch of routes, update every route (recursively) containing specified attribute with the given wrapper. The wrapper fn f is invoked with the old attribute value, and the returned value is updated into the route.

Given a bunch of routes, update every route (recursively) containing specified attribute with the given wrapper. The
wrapper fn f is invoked with the old attribute value, and the returned value is updated into the route.
sourceraw docstring

update-routesclj/s

(update-routes routes f & args)

Given a bunch of routes, update every route-collection (recursively) with f.

Given a bunch of routes, update every route-collection (recursively) with f.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close