Fork me on GitHub
#babashka
<
2020-09-15
>
plexus06:09:21

@borkdude I don't know if you already discovered the limitations of the local-echo-controller? it's not really suitable for lisp, quoting will not work as you would expect

borkdude09:09:23

Fixed in babashka/local-echo, issue/PR here: https://github.com/wavesoft/local-echo/issues/30

borkdude06:09:35

@plexus yes, I’m working on a fork of the local-echo-controller for that. We basically control incomplete input ourselves instead of needing that part of the plugin to do it for us

plexus06:09:29

that's good, local-echo-controller does too much, it should really do only exactly as much as a unix line discipline driver

borkdude06:09:42

@plexus in general a text area with some Clojure syntax plugin may be more ergonomic for web (we already have sci.web playground) but this is a fun idea of yours! Further discussion in #sci

mathpunk17:09:36

hello! I'm trying to talk to an api with babashka curl. Can anyone tell me what is malformed about this request?

(curl/put ""
          {:headers {"PRIVATE-TOKEN" "itIsSecret"
                     "Content-Type" "application/json"}
           :form-params {"description" "I am renaming this pipeline schedule"}})

mathpunk17:09:05

I got an unwrapped curl command to succeed with this, so I guess the above is not equivalent to the command I used

borkdude19:09:53

@mathpunk if you invoke curl with :debug true it will also include the command in the ex-data:

"curl" "--silent" "--show-error" "--location" "--dump-header" "/var/folders/2m/h3cvrr1x4296p315vbk7m32c0000gp/T/babashka.curl5567161590767606780.headers" "--request" "PUT" "-H" "PRIVATE-TOKEN: itIsSecret" "-H" "Content-Type: application/json" "--form" "description=I am renaming this pipeline schedule" ""
Maybe that will help you debug

mathpunk20:09:47

hmm, same result I think: status 400. The output:

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  babashka.curl: status 400
Location: /Users/tomhenderson/lg/tools/./jobs.clj:125:1

----- Context ------------------------------------------------------------------
121:  :body
122:  (json/parse-string))
123:
124:
125: (curl/put ""
     ^--- babashka.curl: status 400
126:           {:headers {"PRIVATE-TOKEN" token
127:                      "Content-Type" "application/json"}
128:            :form-params {"description" "I am renaming this pipeline schedule"}
129:            :debug true})

----- Stack trace --------------------------------------------------------------
babashka.curl/put - <built-in>
user              - /Users/tomhenderson/lg/tools/./jobs.clj:125:1

mathpunk20:09:01

I thought maybe my error was to put both :headers and :form-params in the same map but I guess not

borkdude20:09:45

@mathpunk Could be a bug in babashka/curl. Can you try if this works with e.g. clj-http or httpkit? Next release will have the latter

borkdude20:09:45

@mathpunk Yes, the output is the same but there is extra data in the exception, which you can get with (ex-data *e), e.g. (:command (ex-data *e))

mathpunk20:09:36

alas, first time writing a babashka script, I seem to not quite understand how to require clj-http :thinking_face: or print the ex-data

mathpunk20:09:01

(do
  (curl/put ""
            {:headers {"PRIVATE-TOKEN" token
                       "Content-Type" "application/json"}
             :form-params {"description" "I am renaming this pipeline schedule"}
             :debug true})

  (pprint (:command (ex-data *e))))

mathpunk20:09:08

but the output looks the same to me

borkdude20:09:09

@mathpunk I think I understand the problem. You state: content-type application/json, but that's not what you're sending

mathpunk20:09:27

i thought that was to tell the server what i wanted back

borkdude20:09:36

no, that's accept

mathpunk20:09:12

and there it is! thank you!

borkdude20:09:34

I noticed clj-http automatically makes the content-type "content-type: application/x-www-form-urlencoded" when you use form-params, maybe babashka/curl should too

borkdude20:09:46

but since the user explicitly provides a content-type here, maybe not