Liking cljdoc? Tell your friends :D

io.pedestal.http.route


*print-routing-table*clj

If true, then the routing table is printed to the console at startup, and when it changes.

Defaults to [[dev-mode?]].

If true, then the routing table is printed to the console at startup, and when it changes.

Defaults to [[dev-mode?]].
sourceraw docstring

decode-query-partclj

(decode-query-part string)

Decodes one key or value of URL-encoded UTF-8 characters in a URL query string.

Decodes one key or value of URL-encoded UTF-8 characters in a URL
query string.
sourceraw docstring

encode-query-partclj

(encode-query-part string)

Encodes one key or value for a UTF-8 URL-encoded query string. Encodes space as +.

Encodes one key or value for a UTF-8 URL-encoded query string.
Encodes space as +.
sourceraw docstring

expand-routesclj

(expand-routes & route-specs)

Converts any number of route fragments into a fully expanded routing table.

Route fragments are created by route definitions (such as [[table-routes]]), or when data structures are implicitly converted (via the ExpandableRoutes protocol).

Returns a wrapper object with a :routes key; the routes themselves are verified to have unique route names (or an exception is thrown).

Converts any number of route fragments into a fully expanded routing table.

Route fragments are created by route definitions (such as [[table-routes]]), or when
data structures are implicitly converted (via the [[ExpandableRoutes]] protocol).

Returns a wrapper object with a :routes key; the routes themselves are verified
to have unique route names (or an exception is thrown).
sourceraw docstring

ExpandableRoutescljprotocol

A protocol extended onto types that can be used to convert instances into a [[RoutingFragment]]. The fragments are combined into a routing table by expand-routes.

Built-in implementations map vectors to [[terse-routes]], sets to [[table-routes]], and maps to [[map-routes->vec-routes]].

A protocol extended onto types that can be used to convert instances into a
[[RoutingFragment]].  The fragments are combined into a routing table
by [[expand-routes]].

Built-in implementations map vectors to [[terse-routes]],
sets to [[table-routes]], and maps to [[map-routes->vec-routes]].

-expand-routesclj

(-expand-routes expandable-route-spec)

Generate and return a [[RoutingFragment]] from the data.

Generate and return a [[RoutingFragment]] from the data.
sourceraw docstring

form-action-for-routesclj

(form-action-for-routes routing-table & default-options)

Like 'url-for-routes' but the returned function returns a map with the keys :action, the URL string; and :method, the HTTP verb as a lower-case string. Also, the :method-param is :_method by default, so HTTP verbs other than GET and POST will be converted to POST with the actual verb in the query string.

The routing-table is obtained from expand-routes.

Like 'url-for-routes' but the returned function returns a map with the keys
:action, the URL string; and :method, the HTTP verb as a lower-case
string. Also, the :method-param is :_method by default, so HTTP
verbs other than GET and POST will be converted to POST with the
actual verb in the query string.

The routing-table is obtained from [[expand-routes]].
sourceraw docstring

is-routing-table?clj

(is-routing-table? routing-table)

Returns true if the value is a routing table (as returned from expand-routes).

Returns true if the value is a routing table (as returned from [[expand-routes]]).
sourceraw docstring

method-paramclj

(method-param)
(method-param query-param-or-param-path)

Returns an interceptor that smuggles HTTP verbs through a value in the request. This interceptor must come after the interceptor that populates that value (e.g. query-params or body-params).

query-param-or-param-path may be one of two things:

  • The parameter inside :query-params where the verb will reside.
  • A complete path to a value elsewhere in the request, such as [:query-params :_method] or [:body-params "_method"]

The path [:query-params :_method] is used by default.

Returns an interceptor that smuggles HTTP verbs through a value in
the request. This interceptor must come *after* the interceptor that populates that
value (e.g. query-params or body-params).

query-param-or-param-path may be one of two things:

- The parameter inside :query-params where the verb will
  reside.
- A complete path to a value elsewhere in the request, such as
  [:query-params :_method] or [:body-params "_method"]

The path [:query-params :_method] is used by default.
sourceraw docstring

parse-param-mapclj

(parse-param-map m)
source

parse-path-paramsclj

(parse-path-params request)
source

parse-query-paramsclj

(parse-query-params request)
source

parse-query-stringclj

(parse-query-string string & options)

Parses URL query string (not including the leading '?') into1 a map. options are key-value pairs, valid options are:

:key-fn Function to call on parameter keys (after URL decoding), returns key for the map, default converts to a keyword.

:value-fn Function to call on the key (after passing through key-fn) and parameter value (after URL decoding), returns value for the map, default does nothing.

Parses URL query string (not including the leading '?') into1 a map.
options are key-value pairs, valid options are:

   :key-fn    Function to call on parameter keys (after URL
              decoding), returns key for the map, default converts
              to a keyword.

   :value-fn  Function to call on the key (after passing through
              key-fn) and parameter value (after URL decoding),
              returns value for the map, default does nothing.
sourceraw docstring

path-params-decoderclj

An Interceptor which URL-decodes path parameters. The path parameters are assoc'd into the :request map with key :path-parameters.

This will only operate once per interceptor chain execution, even if it appears multiple times; this prevents failures in existing applications that upgrade to Pedestal 0.6.0, as prior releases incorrectly failed to decode path parameters. Existing applications that upgrade may have this interceptor in some routes which will do nothing (since the path parameters will already have been decoded).

An Interceptor which URL-decodes path parameters.
The path parameters are assoc'd into the :request map with key :path-parameters.

This will only operate once per interceptor chain execution, even if
it appears multiple times; this prevents failures in existing applications
that upgrade to Pedestal 0.6.0, as prior releases incorrectly failed to
decode path parameters. Existing applications that upgrade may have
this interceptor in some routes which will do nothing (since the path parameters
will already have been decoded).
sourceraw docstring

(print-routes routing-table)

Prints a routing-table (from expand-routes) in an easier to read format.

Prints a routing-table (from [[expand-routes]]) in an easier to read format.
sourceraw docstring

query-paramsclj

An interceptor which parses query-string parameters from an HTTP request into a map. Keys in the map are query-string parameter names, as keywords, and values are strings. The map is assoc'd into the request with key :query-params.

An interceptor which parses query-string parameters from an
HTTP request into a map. Keys in the map are query-string parameter
names, as keywords, and values are strings. The map is assoc'd into
the request with key :query-params.
sourceraw docstring

routerclj

(router routing-table)
(router routing-table router-type)

Given the expanded routing table and, optionally, what kind of router to construct, creates and returns a router interceptor.

router-type may be a keyword identifying a known implementation (see router-implementations), or a function that accepts a seq of route maps, and returns a router function.

A router function will be passed the request map, and return nil, or a matching route.

The default router type is :sawtooth.

Given the expanded routing table and, optionally, what kind of router to construct,
creates and returns a router interceptor.

router-type may be a keyword identifying a known implementation (see [[router-implementations]]),
or a function that accepts a seq of route maps, and returns a router function.

A router function will be passed the request map, and return nil, or a matching route.

The default router type is :sawtooth.
sourceraw docstring

router-implementationsclj

Maps from the common router implementations (:map-tree, :prefix-tree, :sawtooth, or :linear-search) to a router constructor function (which accepts a routing table, and returns a Router instance).

Maps from the common router implementations (:map-tree, :prefix-tree, :sawtooth,
or :linear-search) to a router constructor function (which accepts a routing table, and returns a Router instance).
sourceraw docstring

routes-fromcljmacro

(routes-from & route-exprs)

Wraps around one or more expressions that each provide a [[RoutingFragment]].

In production mode (the default) evaluates to a call to expand-routes.

In development mode (see [[dev-mode?]]), evaluates to a function that, when invoked, returns the expressions passed to expand-routes; this is to support a REPL workflow. This works in combination with the extension of [[RouterSpecification]] onto Fn, which requires that the returned routing specification be expanded.

Further, when the expression is a non-local symbol, it is assumed to identify a Var holding the unexpanded routing specification; to avoid capturing the Var's value, the expansion de-references the named Var before passing it to expand-routes.

Wraps around one or more expressions that each provide a [[RoutingFragment]].

In production mode (the default) evaluates to a call to [[expand-routes]].

In development mode (see [[dev-mode?]]), evaluates to a function that, when invoked, returns the expressions
passed to [[expand-routes]]; this
is to support a REPL workflow. This works in combination with the extension of [[RouterSpecification]]
onto Fn, which requires that the returned routing specification be expanded.

Further, when the expression is a non-local symbol, it is assumed to identify a Var holding the unexpanded routing specification;
to avoid capturing the Var's value, the expansion de-references the named Var before passing it to expand-routes.
sourceraw docstring

try-routing-forclj

(try-routing-for routing-table path verb)
(try-routing-for routing-table router-type path verb)

Used for testing; constructs a router from the routing-table and router-type and performs routing on the provided path and verb (e.g., :get or :post).

Uses :sawtooth as the default router, if unspecified; this should match the configuration in the application's service map.

Returns the matched route (a map from the routing table), or nil if routing was unsuccessful.

The matched route has an extra key, :path-params, a map of keyword to string.

The routing-table is obtained from expand-routes.

Used for testing; constructs a router from the routing-table and router-type and performs routing
on the provided path and verb (e.g., :get or :post).

Uses :sawtooth as the default router, if unspecified; this should match the configuration
in the application's service map.

Returns the matched route (a map from the routing table), or nil if routing was unsuccessful.

The matched route has an extra key, :path-params, a map of keyword to string.

The routing-table is obtained from [[expand-routes]].
sourceraw docstring

url-forclj

(url-for route-name & options)

Used by an invoked interceptor (including a handler function) to generate URLs based on a known route name (from the routing specification), and additional data.

This uses a hidden dynamic variable, so it can only be invoked from request processing threads, and only after the routing interceptor has routed the request.

The available options are as described in url-for-routes.

Used by an invoked interceptor (including a handler function)
to generate URLs based on a known route name (from the routing specification),
and additional data.

This uses a hidden dynamic variable, so it can only be invoked
from request processing threads, and only *after* the routing interceptor has routed
the request.

The available options are as described in [[url-for-routes]].
sourceraw docstring

url-for-routesclj

(url-for-routes routing-table & default-options)

Returns a function that generates URL routes (as strings) from the routing table. The returned function has the signature:

    [route-name & options]

Where options are key-value pairs:

KeyValueDescription
:app-nameStringApplication name specified for this route
:requestMapThe original request; it will be merged into the generated link
:paramsMapA map of all parameters; any params not used as path parameters will be added to the query string
:path-paramsMapA map of path parameters only
:strict-path-params?BooleanWhen true will throw an exception if all path-params aren't fulfilled for the URL
:query-paramsMapA map of query-string parameters only
:method-paramKeywordNames the query-string parameter in which to place the HTTP method name (used when not :get or :post)
:contextvariedString, function that returns a string, or symbol that resolves to a function; specifies root context for the URL
:fragmentStringThe fragment part of the URL
:absolute?BooleanTrue to force an absolute URL
:scheme:http, :httpsUsed to override the scheme portion of the URL
:hostStringUsed to override the host portion of the URL
:portIntegerUsed to override the port in the URL

In addition, you may supply default-options to the 'url-for-routes' function, which are merged with the options supplied to the returned function.

Returns a function that generates URL routes (as strings) from the
routing table. The returned function has the signature:

```
    [route-name & options]
```

Where `options` are key-value pairs:

Key           | Value           | Description
---           |---              |---
:app-name     | String          | Application name specified for this route
:request      | Map             | The original request; it will be merged into the generated link
:params       | Map             | A map of all parameters; any params not used as path parameters will be added to the query string
:path-params  | Map             | A map of path parameters only
:strict-path-params? | Boolean  | When true will throw an exception if all path-params aren't fulfilled for the URL
:query-params | Map             | A map of query-string parameters only
:method-param | Keyword         | Names the query-string parameter in which to place the HTTP method name (used when not :get or :post)
:context      | varied          | String, function that returns a string, or symbol that resolves to a function; specifies root context for the URL
:fragment     | String          | The fragment part of the URL
:absolute?    | Boolean         | True to force an absolute URL
:scheme       | :http, :https   | Used to override the scheme portion of the URL
:host         | String          | Used to override the host portion of the URL
:port         | Integer         | Used to override the port in the URL

In addition, you may supply default-options to the 'url-for-routes'
function, which are merged with the options supplied to the returned
function.
sourceraw docstring

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

× close