This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-19
Channels
- # announcements (1)
- # architecture (24)
- # beginners (7)
- # boot (7)
- # cider (1)
- # cljdoc (4)
- # clojure (20)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-dev (1)
- # clojure-italy (1)
- # clojure-spec (36)
- # clojure-uk (11)
- # clojurescript (44)
- # data-science (3)
- # datascript (1)
- # datomic (8)
- # figwheel-main (2)
- # fulcro (29)
- # graphql (9)
- # kaocha (2)
- # keyboards (1)
- # leiningen (3)
- # lumo (5)
- # nrepl (4)
- # off-topic (39)
- # onyx (5)
- # re-frame (2)
- # shadow-cljs (42)
- # tools-deps (18)
- # yada (65)
{:id :authentication
:methods {:post {
:consumes "application/x-www-form-urlencoded"
:parameters {:form {:email String
:password String}}
:response (fn [{:keys [parameters body] :as ctx}]
(println "ctx" (pr-str ctx))
;(println (pr-str body))
(println "parameters" (pr-str parameters))
;(println (pr-str form))
(let [{:keys [email password]} (:body parameters)]
{:token "foo"
:email email
:password password}))}}}
curl -d '[email protected]&password=qwaszx' -X POST -i
HTTP/1.1 400 Bad Request
Content-Length: 129
Content-Type: text/plain;charset=utf-8
Server: Aleph/0.4.4
Connection: Keep-Alive
Date: Sat, 19 Jan 2019 12:01:44 GMT
Bad form fields
{:status 400,
:error
{:email missing-required-key,
:password missing-required-key,
nil disallowed-key}
curl -X POST -i
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Length: 0
Server: Aleph/0.4.4
Connection: Keep-Alive
Date: Sat, 19 Jan 2019 12:03:39 GMT
I give up. It looks like a bug or it is very hard to set POST with form in yada.
@malcolmsparks Can you look on it? I am trying to use POST 2 days. No idea how to do it.It works with JSON and :body, but not with application/x-www-form-urlencodeda and :form
@kwladyka There is a test in yada that obviously works. Why don’t you start with that code and make small changes until it does what you want?
(def foo
(yh/handler
(resource
{:methods
{:post {:parameters {:form {:foo String}}
:consumes "application/x-www-form-urlencoded"
:response (fn [ctx]
(pr-str (:parameters ctx)))}}})))
curl -d 'foo=bar' -X POST -i 356ms Sat Jan 19 13:06:00 2019
HTTP/1.1 400 Bad Request
Content-Length: 89
Content-Type: text/plain;charset=utf-8
Server: Aleph/0.4.4
Connection: Keep-Alive
Date: Sat, 19 Jan 2019 12:20:18 GMT
Bad form fields
{:status 400, :error {:foo missing-required-key, nil disallowed-key}}
(let [response @(h (mock/request :post "/"
{"foo" "bar"}))]
(is (= 200 (:status response)))
(is (= {:form {:foo "bar"}} (edn/read-string (bs/to-string (:body response))))))
This part fail for the same reason as always(deftest post-test
(let [h (handler
(resource
{:methods
{:post {:parameters {:form {:foo s/Str}}
:consumes "application/x-www-form-urlencoded"
:response (fn [ctx]
(pr-str (:parameters ctx)))}}}))]
;; Nil post body
(let [response @(h (mock/request :post "/"))]
(is (= 200 (:status response)))
(is (= {} (edn/read-string (bs/to-string (:body response))))))
;; Form post body
(let [response @(h (mock/request :post "/"
{"foo" "bar"}))]
(is (= 200 (:status response)))
(is (= {:form {:foo "bar"}} (edn/read-string (bs/to-string (:body response))))))))
I have exactly the same codeso maybe it’s your curl request? I use Insomnia for testing REST APIs manually. Maybe it’s something you could try?
if it doesn’t yada is broken. if it passes, it’s something your code that’s different
lein test 37.9s Sat Jan 19 13:31:42 2019
Exception in thread "main" java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter, compiling:(aleph/http/client_middleware.clj:420:7)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7010)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6991)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyze(Compiler.java:6729)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3881)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7005)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyze(Compiler.java:6729)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6420)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6991)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyze(Compiler.java:6729)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5460)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4022)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7001)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6991)
at clojure.lang.Compiler.analyze(Compiler.java:6773)
at clojure.lang.Compiler.access$300(Compiler.java:38)
at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:595)
...
java --version 12.8s Sat Jan 19 13:33:06 2019
java 11.0.1 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
I’d say, start from something that works (the yada test and java 8) and change one thing at a time and keep it working.
also, if you want OSS contributors to help you detect bugs, make the smallest repro possible of your bug and make an issue for it
Wha I am doing is more research if I want to use yada today or wait +1 year, when it will be ready. So I am also checking how community about yada works and if there is somebody who really understand yada and maintenance it. It is part of the decision 🙂
FWIW, yada is used in production environments by its creators, JUXT, and they aren't going away any time soon so this project should be actively maintained for some time
This might be valuable to you: https://www.deps.co/blog/how-to-upgrade-clojure-projects-to-use-java-11/ Personally I haven’t tried upgrading.
if you want help, make a small repro and put it on github. I can’t guess what’s happening on your machine
I think Dominic means that Edge works on Java 11 when used in conjunction with the latest aleph
Probably, but it doesn’t work for me 😕 At least with official releases of yada. Maybe with edge, which is not released, but who know.
Just to make sure there isn't a miscommunication... This is the Edge project that Dominic is talking about
It uses yada and work on Java 11 with latest aleph
It might be worth trying a different approach for the curl and see if you keep getting the same error on the post. Like @borkdude suggested Insomnia, or I quite like httpie
It uses the 1.2.x series of yada, the local thing is something else. Probably the latest yada is used. I did have an issue, which bumping aleph fixed. Given your error is about aleph, and looks similar, I figure it's the same.
I have progress! It start to work, when I created new project, but I don’t have any idea why
oh my god… ring/ring-devel {:mvn/version "1.7.1"}
this as extra-deps in test
alias in deps.edn
makes this issue! It doesn’t have to be (:required ...)
anywhere. Just having this in deps.edn
make this issue. facepalm
Hammock time 😄
(yada/response-for core/graphql :post "/graphql" {:headers {"Content-Type" "application/json"}
:body "{ game_by_id(id: \"1237\") { name designers { name }}}"})
How to use response-for
to send a JSON? (example above doesn’t send :body)
equality of:
curl -H "Content-Type: application/json" -d '{"email":"","password":"qwaszx"}' -X POST -i