-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.bb
31 lines (27 loc) · 1.06 KB
/
http.bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bb
(require '[cheshire.core :as json]
'[babashka.curl :as curl]
'[clojure.java.io :as io])
(comment
;; no need for headers? slurp works
(-> (slurp "https://reqres.in/api/users/2")
(json/parse-string true)
:data :email) ;; => "[email protected]"
;; about basic auth?
(-> "https://postman-echo.com/basic-auth"
(curl/get {:basic-auth ["postman" "password"]})
:body
(json/parse-string true)) ;; => {:authenticated true}
;; logging in and getting token
(-> "https://reqres.in/api/login"
;; (curl/post {:body (json/generate-string {:email "[email protected]" :password "cityslicka"})})
(curl/post {:body (json/generate-string {:email "[email protected]" :password "cityslicka"})
:headers {"Content-Type" "application/json"}})
:body
(json/parse-string true)
:token) ;; => "QpwL5tke4Pnpja7X4"
;; download file
(-> (curl/get "https://github.com/babashka/babashka/raw/master/logo/icon.png"
{:as :bytes})
:body
(io/copy (io/file "icon.png"))))