pedestal.content-negotiation documentation
Content negotiation for Pedestal web services.
content-negotiation
(content-negotiation)
(content-negotiation route-map)
(content-negotiation wildcard-map route-map)
(content-negotiation not-acceptable-response-fn wildcard-map route-map)
Returns an interceptor that performs content negotiation.
On enter, it will attach the first supported content negotiation
route from route-map to ::content-negotiation in request if the
accept headers can be satisfied. Otherwise, it attaches a 406 Not
Acceptable response to the context. The not-acceptable-response-fn
returns a ring response and will be passed the request headers as a
single map argument.
On leave, it will check the status of the response. If the status
is 200, it will update the response body using the function for the
route found on enter and set the "Content-Type" and
"Content-Encoding" headers appropriately, otherwise it will do
nothing.
default-routes
The default set of content negotiation routes that should be
supported in a route-map.
default-wildcard-map
The default wildcard map for use with replace-wildcards.
replace-wildcards
(replace-wildcards route)
(replace-wildcards wildcard-map route)
Replaces any wildcard values in route. A wildcard map contains
values for :charset and :encoding that are used to replace their
corresponding values in route if they are set to "*". It also
contains a map for :content-type that pairs a content-type wildcard
like "application/*" with a replacement value. The default
wildcard map is default-wildcard-map.
route
(route m)
Returns a content negotiation route from a possibly incomplete
route. A route contains the keys :content-type,
:content-type-params, :charset, and :encoding. These correspond to
the "accept", "accept-charset", and "accept-encoding" headers
in an HTTP request. A route specifies exactly one valid setting, so
it is common for an HTTP request's headers to specify many routes.
route-map
(route-map)
(route-map routes)
Returns a map from a set of content negotiation routes to default
functions that can be used to write a clojure object to a pedestal
response body. When no routes are passed in, default-routes are
used. If there is no default function to handle a route passed in,
an ExceptionInfo with :type ::unhandled-route is raised. The
default functions return functions that write to output streams.
routes
(routes headers)
Returns an ordered sequence of content negotiation routes from the
"accept" "accept-charset" and "accept-encoding" headers.
RFC-2616 is followed for prioritization, including the use of the q
parameter.