Fork me on GitHub
#yada
<
2015-11-19
>
stijn09:11:48

@malcolmsparks: do you have an example on how to use multipart/form-data?

nha10:11:32

beginner question : can we control the response type headers ? For instance, if I use :

(yada (fn [ctx]
        "Hello"))
I get a proper answer, but with application/octet-stream, while I would like application/json

nha10:11:30

I am trying that now :

(yada (fn [ctx]
          {:status 202
           :media-type "text/html"
           :body "Hello"}))
But I get a 500 :
#error {
 :cause "Attempt to call render-map without a media-type: {:media-type <#C0702A7SB>.media-type[application/octet-stream;q=1.0]}"
 :data {:representation {:media-type <#C0702A7SB>.media-type[application/octet-stream;q=1.0]}}
 :via

nha10:11:11

Even that (from the user manual) fails for me :

(yada
  (fn [ctx]
    (case (get-in ctx [:response :representation :language])
            "zh-ch" "你好世界!\n"
            "en" "Hello World!\n"))
  :representations [{:media-type "text/plain"
                     :language #{"en" "zh-ch"}
                     :charset "UTF-8"}
                    {:media-type "text/plain"
                     :language "zh-ch"
                     :charset "Shift_JIS;q=0.9"}])
With :
#error {
 :cause "Wrong number of args (3) passed to: core/handler"
 :via
 [{:type clojure.lang.Compiler$CompilerException

stijn12:11:42

nha, if you want to generate custom responses, you need to :

stijn13:11:10

(-> (:response ctx)
  (assoc :status 202 ....)

nha13:11:30

Ah got it, I need to send back the context

stijn13:11:39

or Response

nha13:11:08

Ok trying that now simple_smile

stijn13:11:42

and in order to provide for instance both application/json and application/edn you can provide representations in the yada options

stijn13:11:57

(yada/yada your-fn {:representations [{:media-type "application/json"
                                                                                :charset    "UTF-8"}
                                                                               {:media-type "application/edn"
                                                                                :charset    "UTF-8"}]}

nha13:11:20

This is what I was trying to do ! Thanks a ton

nha13:11:29

So I guess there is no shortcut to return a ring response also, correct ?

stijn13:11:54

you could probably do (merge (->Response) {....})

stijn13:11:17

or (merge (:response ctx) your-ring-response)

nha13:11:05

Ok I see. You first example works, now I am trying the representations.

nha13:11:13

Perfect ! Now I just need to figure how to use the SSE, thanks again

stijn13:11:20

you're welcome, good luck!

imre15:11:51

any idea on how I can enable CORS in a bidi/yada api?

mccraigmccraig15:11:43

imre: this resource shows the headers you need - https://www.refheap.com/37a14e7936326bb7d592304b2

imre15:11:13

thanks a million

malcolmsparks15:11:38

@stijn: you're a bit ahead of me, but the full yada upload story is very close now, it includes async upload of byte-streams, multipart handling and you will be able to specify your own strategies for handling uploads (memory, off-heap, disk, etc..)

malcolmsparks15:11:35

I've also fixes an old issue (#15) by allowing you to specify consumes in swagger

malcolmsparks15:11:14

I've got a new example in the works (selfie) that shows how to do this, and I'll be updating the user-manual too in due course

stijn16:11:55

@malcolmsparks that sounds promising