Liking cljdoc? Tell your friends :D

ring.middleware.format-response


available-charsetsclj

Set of recognised charsets by the current JVM

Set of recognised charsets by the current JVM
sourceraw docstring

can-encode?clj

(can-encode? {:keys [enc-type] :as encoder}
             {:keys [type sub-type] :as accepted-type})

Check whether encoder can encode to accepted-type. Accepted-type should have keys :type and :sub-type with appropriate values.

Check whether encoder can encode to accepted-type.
Accepted-type should have keys *:type* and *:sub-type* with appropriate
values.
sourceraw docstring

choose-charsetclj

Memoized form of choose-charset*

Memoized form of [[choose-charset*]]
sourceraw docstring

choose-charset*clj

(choose-charset* accept-charset)

Returns an useful charset from the accept-charset string. Defaults to utf-8

Returns an useful charset from the accept-charset string.
Defaults to utf-8
sourceraw docstring

default-charset-extractorclj

(default-charset-extractor request)

Default charset extractor, which returns either Accept-Charset header field or utf-8

Default charset extractor, which returns either *Accept-Charset*
header field or *utf-8*
sourceraw docstring

default-formatsclj

source

default-handle-errorclj

(default-handle-error e _ _)

Default error handling function used, which rethrows the Exception

Default error handling function used, which rethrows the Exception
sourceraw docstring

encode-msgpackclj

(encode-msgpack body)
source

encode-msgpack-kwclj

(encode-msgpack-kw body)
source

init-encoderclj

(init-encoder encoder opts)
source

make-encoderclj

(make-encoder encoder content-type)
(make-encoder encoder content-type binary?)

Return a encoder map suitable for [[wrap-format-response.]] f takes a string and returns an encoded string type Content-Type of the encoded string (make-encoder json/generate-string "application/json")

Return a encoder map suitable for [[wrap-format-response.]]
f takes a string and returns an encoded string
type *Content-Type* of the encoded string
(make-encoder json/generate-string "application/json")
sourceraw docstring

make-json-encoderclj

(make-json-encoder pretty options)
source

parse-accept-headerclj

Memoized form of parse-accept-header*

Memoized form of [[parse-accept-header*]]
sourceraw docstring

parse-accept-header*clj

(parse-accept-header* accept-header)

Parse Accept headers into a sorted sequence of maps. "application/json;level=1;q=0.4" => ({:type "application" :sub-type "json" :q 0.4 :level "1"})

Parse Accept headers into a sorted sequence of maps.
"application/json;level=1;q=0.4"
=> ({:type "application" :sub-type "json"
     :q 0.4 :level "1"})
sourceraw docstring

parse-charset-acceptedclj

(parse-charset-accepted v)

Parses an accept-charset string to a list of [charset quality-score]

Parses an *accept-charset* string to a list of [*charset* *quality-score*]
sourceraw docstring

preferred-charsetclj

(preferred-charset charsets)

Returns an acceptable choice from a list of [charset quality-score]

Returns an acceptable choice from a list of [*charset* *quality-score*]
sourceraw docstring

preferred-encoderclj

(preferred-encoder encoders req)

Return the encoder that encodes to the most preferred type. If the Accept header of the request is a String, assume it is according to Ring spec. Else assume the header is a sequence of accepted types sorted by their preference. If no accepted encoder is found, return nil. If no Accept header is found, return the first encoder.

Return the encoder that encodes to the most preferred type.
If the *Accept* header of the request is a *String*, assume it is
according to Ring spec. Else assume the header is a sequence of
accepted types sorted by their preference. If no accepted encoder is
found, return *nil*. If no *Accept* header is found, return the first
encoder.
sourceraw docstring

stringify-keysclj

(stringify-keys m)

Recursively transforms all map keys from keywords to strings with namespace.

Recursively transforms all map keys from keywords to strings with namespace.
sourceraw docstring

wrap-clojure-responseclj

(wrap-clojure-response handler & args)

Wrapper to serialize structures in :body to Clojure native with sane defaults. If :hf is set to true, will use print-dup for high-fidelity printing ( see here ). See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to Clojure native with sane defaults.
If *:hf* is set to true, will use *print-dup* for high-fidelity
printing ( see
[here](https://groups.google.com/d/msg/clojure/5wRBTPNu8qo/1dJbtHX0G-IJ) ).
See [[wrap-format-response]] for more details.
sourceraw docstring

wrap-format-responseclj

(wrap-format-response handler & args)

Wraps a handler such that responses body to requests are formatted to the right format. If no Accept header is found, use the first encoder.

  • :predicate is a predicate taking the request and response as arguments to test if serialization should be used
  • :encoders a sequence of maps given by make-encoder
  • :charset can be either a string representing a valid charset or a fn taking the req as argument and returning a valid charset (utf-8 is strongly suggested)
  • :binary? if true :charset will be ignored and decoder will receive an InputStream
  • :handle-error is a fn with a sig [exception request response]. Defaults to just rethrowing the Exception
Wraps a handler such that responses body to requests are formatted to
 the right format. If no *Accept* header is found, use the first encoder.

+ **:predicate** is a predicate taking the request and response as
                 arguments to test if serialization should be used
+ **:encoders** a sequence of maps given by make-encoder
+ **:charset** can be either a string representing a valid charset or a fn
               taking the req as argument and returning a valid charset
               (*utf-8* is strongly suggested)
+ **:binary?** if true *:charset* will be ignored and decoder will receive
              an *InputStream*
+ **:handle-error** is a fn with a sig [exception request response]. Defaults
                    to just rethrowing the Exception
sourceraw docstring

wrap-json-responseclj

(wrap-json-response handler & args)

Wrapper to serialize structures in :body to JSON with sane defaults. See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to JSON with sane defaults.
See [[wrap-format-response]] for more details.
sourceraw docstring

wrap-msgpack-responseclj

(wrap-msgpack-response handler & args)

Wrapper to serialize structures in :body to msgpack with sane defaults. See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to **msgpack** with sane
defaults. See [[wrap-format-response]] for more details.
sourceraw docstring

wrap-restful-responseclj

(wrap-restful-response handler & args)

Wrapper that tries to do the right thing with the response :body and provide a solid basis for a RESTful API. It will serialize to JSON, YAML, Clojure, Transit or HTML-wrapped YAML depending on Accept header. See wrap-format-response for more details. Recognized formats are :json, :json-kw, :edn :yaml, :yaml-in-html, :transit-json, :transit-msgpack. Options to specific encoders can be passed in using :format-options option. If is a map from format keyword to options map.

Wrapper that tries to do the right thing with the response *:body*
and provide a solid basis for a RESTful API. It will serialize to
JSON, YAML, Clojure, Transit or HTML-wrapped YAML depending on Accept header.
See wrap-format-response for more details. Recognized formats are
*:json*, *:json-kw*, *:edn* *:yaml*, *:yaml-in-html*, *:transit-json*,
*:transit-msgpack*.
Options to specific encoders can be passed in using *:format-options*
option. If is a map from format keyword to options map.
sourceraw docstring

wrap-transit-json-responseclj

(wrap-transit-json-response handler & args)

Wrapper to serialize structures in :body to transit over JSON with sane defaults. See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to transit over **JSON** with sane defaults.
See [[wrap-format-response]] for more details.
sourceraw docstring

wrap-transit-msgpack-responseclj

(wrap-transit-msgpack-response handler & args)

Wrapper to serialize structures in :body to transit over msgpack with sane defaults. See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to transit over **msgpack** with sane defaults.
See [[wrap-format-response]] for more details.
sourceraw docstring

wrap-yaml-in-html-responseclj

(wrap-yaml-in-html-response handler & args)

Wrapper to serialize structures in :body to YAML wrapped in HTML to check things out in the browser. See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to YAML wrapped in HTML to
check things out in the browser. See [[wrap-format-response]] for more
details.
sourceraw docstring

wrap-yaml-responseclj

(wrap-yaml-response handler & args)

Wrapper to serialize structures in :body to YAML with sane defaults. See wrap-format-response for more details.

Wrapper to serialize structures in *:body* to YAML with sane
defaults. See [[wrap-format-response]] for more details.
sourceraw docstring

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

× close