branch: externals/plz
commit dd92f488950dc43e05854be99a3a4e69c90812a2
Author: Adam Porter <[email protected]>
Commit: Adam Porter <[email protected]>
Change: Default to :then 'sync and :as 'string
This is most convenient for simple uses.
---
README.org | 19 ++++++++++++++-----
plz.el | 3 ++-
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/README.org b/README.org
index 06e9f7c48c..8f464f16b3 100644
--- a/README.org
+++ b/README.org
@@ -46,11 +46,21 @@ The only public function is ~plz~, which sends an HTTP
request and returns eithe
** Examples
+Synchronously =GET= a URL and return the response body as a decoded string
(here, raw JSON):
+
+#+BEGIN_SRC elisp :exports both :results value code
+ (plz 'get "https://httpbin.org/user-agent")
+#+END_SRC
+
+#+RESULTS:
+#+BEGIN_SRC elisp
+ "{\n \"user-agent\": \"curl/7.35.0\"\n}\n"
+#+END_SRC
+
Synchronously =GET= a URL that returns a JSON object, and parse and return it
as an alist:
#+BEGIN_SRC elisp :exports both :results value code
- (plz 'get "https://httpbin.org/get"
- :as #'json-read :then 'sync)
+ (plz 'get "https://httpbin.org/get" :as #'json-read)
#+END_SRC
#+RESULTS:
@@ -81,8 +91,7 @@ Asynchronously =POST= a JSON object in the request body, then
parse a JSON objec
Synchronously download a JPEG file, then create an Emacs image object from the
data:
#+BEGIN_SRC elisp :exports both
- (let ((jpeg-data (plz 'get "https://httpbin.org/image/jpeg"
- :as 'binary :then 'sync)))
+ (let ((jpeg-data (plz 'get "https://httpbin.org/image/jpeg" :as 'binary)))
(create-image jpeg-data nil 'data))
#+END_SRC
@@ -91,7 +100,7 @@ Synchronously download a JPEG file, then create an Emacs
image object from the d
** Functions
-+ ~plz~ :: /(method url &key headers body as then else finally noquery
(body-type 'text) (decode t decode-s) (connect-timeout plz-connect-timeout)
(timeout plz-timeout))/
++ ~plz~ :: /(method url &key headers body else finally noquery (as 'string)
(then 'sync) (body-type 'text) (decode t decode-s) (connect-timeout
plz-connect-timeout) (timeout plz-timeout))/
Request ~METHOD~ from ~URL~ with curl. Return the curl process object or,
for a synchronous request, the selected result.
diff --git a/plz.el b/plz.el
index ab4f4f89a5..86a9a270b5 100644
--- a/plz.el
+++ b/plz.el
@@ -212,7 +212,8 @@ connection phase and waiting to receive the response (the
;;;;; Public
-(cl-defun plz (method url &key headers body as then else finally noquery
+(cl-defun plz (method url &key headers body else finally noquery
+ (as 'string) (then 'sync)
(body-type 'text) (decode t decode-s)
(connect-timeout plz-connect-timeout) (timeout
plz-timeout))
"Request METHOD from URL with curl.