yada

kwladyka 2019-01-19T12:05:31.159300Z

{: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&amp;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.

kwladyka 2019-01-19T12:07:20.159800Z

It works with JSON and :body, but not with application/x-www-form-urlencodeda and :form

borkdude 2019-01-19T12:16:03.160400Z

@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?

kwladyka 2019-01-19T12:20:57.160900Z

The code from test doesn’t work for me when use real (curl not mock) request

kwladyka 2019-01-19T12:21:51.161300Z

(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}}

kwladyka 2019-01-19T12:26:55.161700Z

saying more copy & paste this test doesn’t work for me

kwladyka 2019-01-19T12:27:47.162Z

(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

kwladyka 2019-01-19T12:28:22.162400Z

(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 code

kwladyka 2019-01-19T12:28:36.162600Z

@borkdude ^

kwladyka 2019-01-19T12:29:21.163300Z

I don’t know. It could a bug in yada. I give up.

borkdude 2019-01-19T12:29:23.163500Z

so maybe it’s your curl request? I use Insomnia for testing REST APIs manually. Maybe it’s something you could try?

kwladyka 2019-01-19T12:29:39.163800Z

But even this test with mock fail

kwladyka 2019-01-19T12:29:45.164Z

exactly the same code as in yada tests

kwladyka 2019-01-19T12:29:51.164300Z

so it is not about curl request

borkdude 2019-01-19T12:30:05.164800Z

ok. when you run the yada tests on your machine, does that test pass?

borkdude 2019-01-19T12:30:48.165400Z

if it doesn’t yada is broken. if it passes, it’s something your code that’s different

kwladyka 2019-01-19T12:32:31.165900Z

no, it fail but with different error

borkdude 2019-01-19T12:32:43.166100Z

can you show the error?

kwladyka 2019-01-19T12:33:24.166400Z

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)
...

borkdude 2019-01-19T12:33:49.166600Z

what dependencies are you using?

kwladyka 2019-01-19T12:34:15.166900Z

I did git clone yada

borkdude 2019-01-19T12:34:24.167200Z

what java version are you using?

kwladyka 2019-01-19T12:34:38.167400Z

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)

borkdude 2019-01-19T12:34:52.167700Z

that might be it then. a lot of libraries don’t support java 11 yet

kwladyka 2019-01-19T12:35:11.168Z

ok this errror could be about this, but it doesn’t explain POST issue

kwladyka 2019-01-19T12:36:16.168400Z

Because I have no errors there

borkdude 2019-01-19T12:37:01.169300Z

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.

borkdude 2019-01-19T12:37:48.169900Z

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

kwladyka 2019-01-19T12:40:37.170300Z

it pass in docker on ubuntu

kwladyka 2019-01-19T12:50:15.171900Z

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 🙂

kwladyka 2019-01-19T12:51:29.172300Z

lein test doesn’t work with Java 11

borkdude 2019-01-19T12:56:20.172700Z

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.

kwladyka 2019-01-19T13:01:51.173200Z

I could try but it still doesn’t explain POST issue 😛

borkdude 2019-01-19T13:03:44.173900Z

All I’m saying is that Java 11 isn’t the defacto standard yet in clojure land.

kwladyka 2019-01-19T13:08:37.174300Z

I understand, but this are probable 2 different issues.

kwladyka 2019-01-19T13:09:05.174600Z

that is what I am trying to say 🙂

borkdude 2019-01-19T13:09:53.175300Z

if you want help, make a small repro and put it on github. I can’t guess what’s happening on your machine

kwladyka 2019-01-19T13:10:02.175500Z

Sure, thank you

kwladyka 2019-01-19T13:18:28.176Z

jdk1.8.0_192.jdk doesn’t work too

kwladyka 2019-01-19T13:19:06.176300Z

I am so curious what is the issue 🙂

dominicm 2019-01-19T14:26:36.176500Z

Update aleph

kwladyka 2019-01-19T14:51:02.178Z

I was trying with the newest version also

kwladyka 2019-01-19T14:51:18.178600Z

Or should I use older one?

dominicm 2019-01-19T14:55:29.178800Z

Edge worked on 11 if I just used the latest aleph

kwladyka 2019-01-19T15:33:32.179700Z

11? aleph 0.4.6 ? There is no 11

kwladyka 2019-01-19T17:18:29.180Z

the same with 0.4.7-alpha2

yogidevbear 2019-01-19T17:22:42.180200Z

I think Dominic means that Edge works on Java 11 when used in conjunction with the latest aleph

kwladyka 2019-01-19T17:23:50.180500Z

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.

kwladyka 2019-01-19T17:24:01.180700Z

So.. only I have this issue? 😕

yogidevbear 2019-01-19T17:24:56.180900Z

https://github.com/juxt/edge

yogidevbear 2019-01-19T17:25:58.181200Z

Just to make sure there isn't a miscommunication... This is the Edge project that Dominic is talking about

yogidevbear 2019-01-19T17:26:23.181400Z

It uses yada and work on Java 11 with latest aleph

kwladyka 2019-01-19T17:28:04.181600Z

but it use yada from local folders, not from clojars

kwladyka 2019-01-19T17:30:14.181800Z

I mean I can’t compare it because of that

yogidevbear 2019-01-19T17:39:03.182200Z

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

kwladyka 2019-01-19T17:39:19.182700Z

I have progress! It start to work, when I created new project, but I don’t have any idea why

kwladyka 2019-01-19T17:39:28.183Z

But it is very close to figure it out

👍 1
kwladyka 2019-01-19T17:47:17.184600Z

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

yogidevbear 2019-01-19T17:48:04.184700Z

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

kwladyka 2019-01-19T17:48:24.185200Z

It is good to take a break during debugging and come back with fresh mind

💯 1
yogidevbear 2019-01-19T17:48:52.185500Z

Hammock time 😄

kwladyka 2019-01-19T17:56:10.187300Z

I have to say it was the most stupid Clojure bug which I ever had 🤦

kwladyka 2019-01-19T17:56:14.187500Z

Thank you all for support

dominicm 2019-01-19T19:09:17.187600Z

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.

kwladyka 2019-01-19T19:48:56.188Z

(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>