yada

2018-04-14T10:08:03.000078Z

@stijn generating a body from xml:

2018-04-14T10:08:19.000074Z

(extend-protocol yada.body/MessageBody
  clojure.data.xml.Element
  (to-body [cdxe representation]
    (clojure.data.xml/emit-str cdxe))
  (content-length [out]
    nil ;; let default logic get length of string body
    ))

(defn make-server []
  (yada/listener
   ["/" (yada/resource
         {:methods
          {:get
           {:produces #{"application/xml"}
            :response
            (fn [ctx]
              #clojure.data.xml.Element{:tag :p,
                                        :attrs {},
                                        :content ["hello "
                                                  #clojure.data.xml.Element{:tag :b,
                                                                            :attrs {},
                                                                            :content ["world"]}]})}}})]
   {:port 3000}))

;; curl -vv "<http://localhost:3000>" -H "Accept: application/xml"
;; &gt; GET / HTTP/1.1
;; &gt; Accept: application/xml
;; &gt; 
;; &lt; HTTP/1.1 200 OK
;; &lt; Content-Type: application/xml
;; &lt; content-length: 63
;; &lt; 
;; &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;p&gt;hello &lt;b&gt;world&lt;/b&gt;&lt;/p&gt;