Fork me on GitHub
#yada
<
2017-07-11
>
skylar07:07:27

Hi guys! I am new with Yada and I would like to know if one can use buddy with yada.

malcolmsparks07:07:20

Yes. In fact, yada depends on buddy for some security features. See ext/oauth2 and ext/jwt

skylar07:07:55

Sounds good! Thanks @malcolmsparks

danielcompton09:07:35

Are there any examples testing a mock POST request with a body?

danielcompton09:07:51

I'm having trouble replicating the behaviour that the web server does

danielcompton09:07:15

(defn response-for
  "Same as yada.test response-for, but returns a Clojure data body.

  Produces yada responses for a number of types. Maps are interpreted
  as resource-maps, vectors are bidi routes. If you want these as
  bodies, use (response-for {:response …})"
  ([o]
   (response-for o :get "/" {}))
  ([o method]
   (response-for o method "/" {}))
  ([o method uri]
   (response-for o method uri {}))
  ([o method uri options]
   (let [h (as-handler o)
         response @(h (yada/request-for method uri options))]
     (cond-> response
             (:body response) (update :body (comp edn/read-string b/to-string))))))

(defn response-for-query
  ([o named-query]
   (response-for-query o named-query {}))
  ([o named-query params]
   (response-for o :get (str "/queries/" (cqrs/query-url named-query)) params)))

(defn response-for-command
  ([o command]
   (response-for o :post "/commands/" {:headers {"content-type" "application/edn"}
                                       :body (b/to-byte-buffer (prn-str command))})))
I have this ^^

danielcompton09:07:46

and in response-for-command I'm trying to create a body that is readable by Yada

danielcompton09:07:53

Ah, the bit I was missing is that I wasn't setting a content-length