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?
huh i've not had any problems with POST resources with bodies at all - and i have lots of them
your resource definition looks pretty much like one of mine
e.g. https://gist.github.com/mccraigmccraig/27d56b41fce74b212d5cdff3eec61ddc
although i've never used the response-for
test fn
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)
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)))))
dunno - it looks from the source like response-for
should work with non-GET methods
(req (test.system/routes) (-> (mock/request :put "/my/put/path" "cdeeee89f8910a13494ff85010d044834c4ad448")
(basic-auth)))
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 🙂But 415 is a media type problem, so it may not help
Yes - I wish there was a debug mode with extra logging
Not a bad idea. I think liberator has something like that, where it reports back the path it went down
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))))
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"}
Ah I have to remove the extra body
. It works !
Thanks a lot guys 😄
Not the first time I am saved in this channel 😛