From 088699e19c7fca0c6e23d0316a56b5729763bc20 Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Wed, 5 Apr 2023 10:30:04 -0400 Subject: janet: add convenience functions slurp and spit these are currently to be considered unstable, fully undocumented. to be stabilized in an official release later, assuming they don't need any changes --- jurl/init.janet | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jurl/init.janet b/jurl/init.janet index 0d501ca..ad6c0a4 100644 --- a/jurl/init.janet +++ b/jurl/init.janet @@ -272,6 +272,19 @@ :headers (text/parse-headers res-hdr) :status (handle :response-code)}) +# fast and convenient functions +(defn slurp + [url &opt opts] + (default opts {}) + (def out (request (merge opts {:url url}))) + (assert (= :ok (out :error))) + (out :body)) + +(defn spit + [url body &opt opts] + (default opts {}) + (def out (request (merge opts {:url url :method :post :body body})))) + (defn- merge-request [orig new] (let [mdict |(merge (get orig $ {}) (get new $ {}))] -- cgit v1.2.3