Fork me on GitHub
#yada
<
2019-01-19
>
kwladyka12:01:31

{: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.

kwladyka12:01:20

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

borkdude12:01:03

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

kwladyka12:01:57

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

kwladyka12:01:51

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

kwladyka12:01:55

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

kwladyka12:01:47

(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

kwladyka12:01:22

(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

kwladyka12:01:21

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

borkdude12:01:23

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

kwladyka12:01:39

But even this test with mock fail

kwladyka12:01:45

exactly the same code as in yada tests

kwladyka12:01:51

so it is not about curl request

borkdude12:01:05

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

borkdude12:01:48

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

kwladyka12:01:31

no, it fail but with different error

borkdude12:01:43

can you show the error?

kwladyka12:01:24

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

borkdude12:01:49

what dependencies are you using?

kwladyka12:01:15

I did git clone yada

borkdude12:01:24

what java version are you using?

kwladyka12:01:38

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)

borkdude12:01:52

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

kwladyka12:01:11

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

kwladyka12:01:16

Because I have no errors there

borkdude12:01:01

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.

borkdude12:01:48

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

kwladyka12:01:37

it pass in docker on ubuntu

kwladyka12:01:15

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 🙂

yogidevbear17:01:04

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

kwladyka12:01:29

lein test doesn’t work with Java 11

borkdude12:01:20

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.

kwladyka13:01:51

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

borkdude13:01:44

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

kwladyka13:01:37

I understand, but this are probable 2 different issues.

kwladyka13:01:05

that is what I am trying to say 🙂

borkdude13:01:53

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

kwladyka13:01:02

Sure, thank you

kwladyka13:01:28

jdk1.8.0_192.jdk doesn’t work too

kwladyka13:01:06

I am so curious what is the issue 🙂

dominicm14:01:36

Update aleph

kwladyka14:01:02

I was trying with the newest version also

kwladyka14:01:18

Or should I use older one?

dominicm14:01:29

Edge worked on 11 if I just used the latest aleph

kwladyka15:01:32

11? aleph 0.4.6 ? There is no 11

kwladyka17:01:29

the same with 0.4.7-alpha2

yogidevbear17:01:42

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

kwladyka17:01:50

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.

kwladyka17:01:01

So.. only I have this issue? 😕

yogidevbear17:01:58

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

yogidevbear17:01:23

It uses yada and work on Java 11 with latest aleph

kwladyka17:01:04

but it use yada from local folders, not from clojars

kwladyka17:01:14

I mean I can’t compare it because of that

yogidevbear17:01:03

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

dominicm19:01:17

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.

kwladyka17:01:19

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

kwladyka17:01:28

But it is very close to figure it out

👍 5
kwladyka17:01:17

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

kwladyka17:01:24

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

💯 5
yogidevbear17:01:52

Hammock time 😄

kwladyka17:01:10

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

kwladyka17:01:14

Thank you all for support

kwladyka19:01:56

(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