{: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=foo@example.com&password=qwaszx' -X POST -i <http://localhost:3000/authentication>
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://localhost:3000/authentication>
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?
The code from test doesn’t work for me when use real (curl not mock) request
(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 <http://localhost:3000/foo> 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}}
saying more copy & paste this test doesn’t work for me
(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 codeI don’t know. It could a bug in yada. I give up.
so maybe it’s your curl request? I use Insomnia for testing REST APIs manually. Maybe it’s something you could try?
But even this test with mock fail
exactly the same code as in yada tests
so it is not about curl request
ok. when you run the yada tests on your machine, does that test pass?
if it doesn’t yada is broken. if it passes, it’s something your code that’s different
no, it fail but with different error
can you show the error?
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)
...
what dependencies are you using?
I did git clone yada
what java version are you using?
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)
that might be it then. a lot of libraries don’t support java 11 yet
ok this errror could be about this, but it doesn’t explain POST issue
Because I have no errors there
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
it pass in docker on ubuntu
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 🙂
lein test
doesn’t work with Java 11
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.
I could try but it still doesn’t explain POST issue 😛
All I’m saying is that Java 11 isn’t the defacto standard yet in clojure land.
I understand, but this are probable 2 different issues.
that is what I am trying to say 🙂
if you want help, make a small repro and put it on github. I can’t guess what’s happening on your machine
Sure, thank you
jdk1.8.0_192.jdk
doesn’t work too
I am so curious what is the issue 🙂
Update aleph
I was trying with the newest version also
Or should I use older one?
Edge worked on 11 if I just used the latest aleph
11? aleph 0.4.6 ? There is no 11
the same with 0.4.7-alpha2
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.
So.. only I have this issue? 😕
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
but it use yada from local folders, not from clojars
I mean I can’t compare it because of that
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
I have progress! It start to work, when I created new project, but I don’t have any idea why
But it is very close to figure it out
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
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
It is good to take a break during debugging and come back with fresh mind
Hammock time 😄
I have to say it was the most stupid Clojure bug which I ever had 🤦
Thank you all for support
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.
(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":"<mailto:foo@example.com|foo@example.com>","password":"qwaszx"}' -X POST -i <http://localhost:3000/graphql>