Liking cljdoc? Tell your friends :D

calfpath.route


*routes*

source

assoc-kv-middleware

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

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

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

assoc-route-to-request-middleware

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

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

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

compile-routes

(compile-routes route-specs)
(compile-routes
  route-specs
  {: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 route specs, 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 spec
: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 spec
: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 specs and move the rest into nested specs

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

Given a collection of route specs, 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 spec                                |
|`: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 spec                              |
|`: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 specs and move the rest into nested specs        |

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

conj-fallback-400

(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-405

(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-match

(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

dispatch

(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-routes

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

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])}
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-matchex

(ensure-matchex route-spec matchex)

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

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

lift-key-middleware

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

Given a route spec, lift keys and one or more conflict keys, if the spec 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 spec.

Given a route spec, lift keys and one or more conflict keys, if the spec 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 spec.
sourceraw docstring

make-dispatcher

(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-ensurer

(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-index

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

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

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-matcher

(make-method-matcher route-spec method-finder)

Given a route spec 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 spec already contains the :matcher key or if it does not contain HTTP-method keyword/set then the route spec is left intact. When adding matcher also add matchex unless the :matchex key already exists.

Given a route spec 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 spec already
contains the :matcher key or if it does not contain HTTP-method keyword/set then the route spec is left intact. When
adding matcher also add matchex unless the :matchex key already exists.
sourceraw docstring

make-updater

(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-matcher

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

Given a route spec 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 spec already contains the :matcher key or if it does not contain URI-pattern then the route spec is left intact. When adding matcher also add matchex unless the :matchex key already exists.

Given a route spec 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 spec already contains the :matcher key or if it
does not contain URI-pattern then the route spec is left intact. When adding matcher also add matchex unless the
:matchex key already exists.
sourceraw docstring

prewalk-routes

(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-uri

(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-tidy

(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->request

(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:

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

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-middleware

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

Given a route spec, 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 spec, 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-route

(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-400

(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-405

(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-route

(update-in-each-route specs 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-routes

(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