How to set custom header names in handlers, actions and predicates?

32 views
Skip to first unread message

Hussein B.

unread,
Aug 27, 2015, 10:29:14 AM8/27/15
to Liberator
Hi,

In our organization, we are using JSON but use our special header for that. For example:

application/x.company.project+json;version=1

And when there is error:

application/proplery+json

How to set those headers in actions, predicates and handlers?

Philipp Meier

unread,
Aug 28, 2015, 4:02:13 AM8/28/15
to clojure-...@googlegroups.com
Hi Hussein,

Am 27.08.15 um 16:29 schrieb Hussein B.:
You need to declare the media-type as the available media-type. When the handler returns
String, File or an InputStream, then liberator will use this  the response body:

(defresource foo
    :available-media-types ["application/x.company.project+json;version=1"]
    :handle-ok (fn [ctx] "{\"msg\": \"json with custom content-type\"}"))

If you want to use liberator's representation generation for maps and sequences the you'll need define a multimethod implementation for it:

(defmethod liberator.representation/render-map-generic "application/x.company.project+json;version=1" [data ctx]
  (json/write-str data))

(defmethod liberator.representation/render-seq-generic "application/x.company.project+json;version=1" [data ctx]
  (json/write-str data))


-billy.
--
Philipp Meier





-- 
--
Philipp Meier

Hussein B.

unread,
Aug 28, 2015, 9:43:07 AM8/28/15
to Liberator
Hi,

If I used:

:available-media-types ["application/x.company.project+json;version=1" "application/proplery+json"]


How liberator is going to use "application/property+json in case of 404, 500 or any thing like that?

Thanks a lot.
Reply all
Reply to author
Forward
0 new messages