diff options
| author | 2023-04-05 10:30:04 -0400 | |
|---|---|---|
| committer | 2023-04-05 10:30:04 -0400 | |
| commit | 088699e19c7fca0c6e23d0316a56b5729763bc20 (patch) | |
| tree | 0fdb864c1bc2c11a9a94bef3fa760f68c260c353 | |
| parent | meta: release 1.1.3 (diff) | |
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
| -rw-r--r-- | jurl/init.janet | 13 |
1 files changed, 13 insertions, 0 deletions
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 $ {}))] |
