Next: , Previous: , Up: Emacs Lisp   [Contents][Index]


17.16 emacs-request

“Easy HTTP request for Emacs Lisp”

Examples

GET

(request "http://httpbin.org/get"
  :params '(("key" . "value") ("key2" . "value2"))
  :parser 'json-read
  :success (cl-function
            (lambda (&key data &allow-other-keys)
              (message "I sent: %S" (assoc-default 'args data)))))

POST

(request "http://httpbin.org/post"
  :type "POST"
  :data '(("key" . "value") ("key2" . "value2"))
  ;; :data "key=value&key2=value2"  ;; this is equivalent
  :parser 'json-read
  :success (cl-function
            (lambda (&key data &allow-other-keys)
              (message "I sent: %S" (assoc-default 'form data)))))

Block until completion:

(request "http://httpbin.org/get"
  :sync t
  :complete (cl-function
             (lambda (&key response &allow-other-keys)
               (message "Done: %s" (request-response-status-code response)))))

Curl authentication:

(request "http://httpbin.org/get"
  :auth "digest" ;; or "basic", "anyauth", etc., which see curl(1)
  :complete (cl-function
             (lambda (&key response &allow-other-keys)
               (message "Done: %s" (request-response-status-code response)))))