Liking cljdoc? Tell your friends :D

ring.middleware.format-response


can-encode?clj

(can-encode? encoder 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.
raw docstring

make-encoderclj

(make-encoder encoder content-type)

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")
raw docstring

parse-accept-headerclj


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.
raw docstring

serializable?clj

(serializable? _ {:keys [body]})

Predicate that returns true whenever the response body is not a String, File or InputStream.

Predicate that returns true whenever the response body is not a
String, File or InputStream.
raw docstring

sort-by-checkclj

(sort-by-check by check headers)

wrap-format-responseclj

(wrap-format-response handler & {:keys [predicate encoders charset]})

Wraps a handler such that responses body to requests are formatted to the right format. If no acceptable encoder is found, return 406 response. 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).

Wraps a handler such that responses body to requests are formatted to
the right format.
If no acceptable encoder is found, return 406 response. 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).
raw docstring

wrap-json-responseclj

(wrap-json-response handler
                    &
                    {:keys [predicate encoder type charset]
                     :or {predicate serializable?
                          encoder json/encode
                          type "application/json"
                          charset "utf-8"}})

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.
raw docstring

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

× close