This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-19
Channels
- # aws (4)
- # aws-lambda (2)
- # beginners (67)
- # boot (38)
- # cider (32)
- # cljs-dev (12)
- # cljsrn (2)
- # clojars (2)
- # clojure (190)
- # clojure-chicago (1)
- # clojure-dusseldorf (2)
- # clojure-germany (1)
- # clojure-greece (3)
- # clojure-italy (5)
- # clojure-russia (6)
- # clojure-spec (47)
- # clojure-uk (10)
- # clojurescript (59)
- # cursive (9)
- # data-science (14)
- # datomic (24)
- # devops (16)
- # emacs (8)
- # fulcro (25)
- # graphql (30)
- # hoplon (123)
- # juxt (15)
- # lambdaisland (2)
- # leiningen (4)
- # luminus (6)
- # lumo (9)
- # off-topic (11)
- # om (7)
- # onyx (8)
- # re-frame (14)
- # reagent (5)
- # ring-swagger (5)
- # shadow-cljs (46)
- # spacemacs (41)
- # specter (8)
- # testing (8)
- # unrepl (31)
- # yada (18)
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
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
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))))