yada

2017-10-19T19:24:13.000107Z

Note: the above does not seem related to the media-type. I've tried edn and json, it behave similarly. It there a way to make a POST to a resource in the REPL?

mccraigmccraig 2017-10-19T19:26:44.000240Z

huh i've not had any problems with POST resources with bodies at all - and i have lots of them

mccraigmccraig 2017-10-19T19:27:18.000562Z

your resource definition looks pretty much like one of mine

mccraigmccraig 2017-10-19T19:30:58.000175Z

although i've never used the response-for test fn

2017-10-19T19:31:02.000096Z

Thanks - look similar indeed. Maybe it is that yada/response-for is not supposed to be used like that? (it works for GET requests though)

danielcompton 2017-10-19T19:33:49.000368Z

I have this test function I use a lot

(defn req
  "Like yada.test/response-for, but takes a fully formed request (maybe a mock request)."
  ([o request]
   (let [h        (yada.handler/as-handler o)
         response @(h request)]
     (cond-> response
             (:body response) (update :body b/to-string)))))

mccraigmccraig 2017-10-19T19:34:21.000369Z

dunno - it looks from the source like response-for should work with non-GET methods

danielcompton 2017-10-19T19:34:23.000400Z

(req (test.system/routes) (-> (mock/request :put "/my/put/path" "cdeeee89f8910a13494ff85010d044834c4ad448")
                                       (basic-auth)))

2017-10-19T19:36:23.000435Z

Example get:

(:body (yada/response-for
         (yada/resource {:methods {:get {:consumes #{"application/json"}
                                         :produces #{"application/json"}
                                         :parameters {:query {:foo s/Str}}
                                         :response (fn [ctx]
                                                     {:parameters (:parameters ctx)})}}})
         :get
         "some-route?foo=abc"
         {:headers {"accept" "application/json"}}))
I will try your method now Daniel 🙂

danielcompton 2017-10-19T19:36:57.000151Z

But 415 is a media type problem, so it may not help

2017-10-19T19:37:45.000186Z

Yes - I wish there was a debug mode with extra logging

danielcompton 2017-10-19T19:39:15.000374Z

Not a bad idea. I think liberator has something like that, where it reports back the path it went down

2017-10-19T19:46:10.000122Z

Hm am I doing something wrong?

(let [body (json/generate-string {:foo "a-string"})
      l (str (count body))]
  (req ["/test/" (yada/resource {:methods {:put {:consumes #{"application/json"}
                                                 :produces #{"application/json"}
                                                 :parameters {:body {:foo s/Str}}
                                                 :response (fn [ctx]
                                                             {:parameters (:parameters ctx)})}}})]
       (-> (mock/request :put "/test/" {:body body})
           (mock/content-type "application/json")
           (mock/content-length l))))

2017-10-19T19:46:24.000476Z

I get :

{:status 400, :headers {"content-length" "32", "content-type" "text/plain;charset=utf-8"}, :body "Malformed body\r\n\r\n{:status 400}\n"}

2017-10-19T19:48:15.000258Z

Ah I have to remove the extra body. It works !

2017-10-19T19:49:07.000545Z

Thanks a lot guys 😄

2017-10-19T19:49:31.000358Z

Not the first time I am saved in this channel 😛