babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
plexus 2020-09-15T06:33:21.222400Z

@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

borkdude 2020-09-15T09:28:23.230800Z

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

borkdude 2020-09-15T06:35:35.224400Z

@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

plexus 2020-09-15T06:36:29.225Z

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

borkdude 2020-09-15T06:39:42.227700Z

@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

mathpunk 2020-09-15T17:54:36.232400Z

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

(curl/put "<https://gitlab.logicgate.com/api/v4/projects/97/pipeline_schedules/111>"
          {:headers {"PRIVATE-TOKEN" "itIsSecret"
                     "Content-Type" "application/json"}
           :form-params {"description" "I am renaming this pipeline schedule"}})

mathpunk 2020-09-15T17:55:05.233Z

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

borkdude 2020-09-15T19:55:53.233800Z

@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" "<https://gitlab.logicgate.com/api/v4/projects/97/pipeline_schedules/111>"
Maybe that will help you debug

mathpunk 2020-09-15T20:06:47.234400Z

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 "<https://gitlab.logicgate.com/api/v4/projects/97/pipeline_schedules/111/>"
     ^--- 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 - &lt;built-in&gt;
user              - /Users/tomhenderson/lg/tools/./jobs.clj:125:1

mathpunk 2020-09-15T20:08:01.235400Z

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

borkdude 2020-09-15T20:12:45.235800Z

@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

borkdude 2020-09-15T20:13:45.236400Z

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

mathpunk 2020-09-15T20:19:36.237600Z

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

mathpunk 2020-09-15T20:20:01.238200Z

(do
  (curl/put "<https://gitlab.logicgate.com/api/v4/projects/97/pipeline_schedules/111/>"
            {:headers {"PRIVATE-TOKEN" token
                       "Content-Type" "application/json"}
             :form-params {"description" "I am renaming this pipeline schedule"}
             :debug true})

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

mathpunk 2020-09-15T20:20:08.238500Z

but the output looks the same to me

borkdude 2020-09-15T20:20:09.238600Z

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

mathpunk 2020-09-15T20:20:21.238800Z

ohhhh

mathpunk 2020-09-15T20:20:27.239100Z

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

borkdude 2020-09-15T20:20:36.239300Z

no, that's accept

mathpunk 2020-09-15T20:21:12.240Z

and there it is! thank you!

borkdude 2020-09-15T20:21:34.240300Z

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

borkdude 2020-09-15T20:21:46.240600Z

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

borkdude 2020-09-15T20:21:54.240800Z

np :)