Damien Gonot
Home Blog Notes About

Emacs Lisp

Homepage / Notes / Computer Science / Programming Languages / Niche Languages / Emacs Lisp

Basics

(princ "Hello, World!")
Hello, World!
(+ 2 2)
4
(setq name "Damien")
Damien

HTTP Request

Using url-retrieve-synchronously

(defun http-get (url)
  "Make a HTTP GET request to URL and return the response body as a string."
  (with-current-buffer (url-retrieve-synchronously url)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (while (looking-at-p "\n")
      (forward-char 1))
    (buffer-substring-no-properties (point) (point-max))))

(http-get "https://httpbin.org/get")
{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Accept-Encoding": "gzip",
    "Extension": "Security/Digest Security/SSL",
    "Host": "httpbin.org",
    "Mime-Version": "1.0",
    "User-Agent": "URL/Emacs Emacs/28.2 (OpenStep; aarch64-apple-darwin21.6.0)",
    "X-Amzn-Trace-Id": "Root=1-64452ce7-2e5e19c67e996e6809c55d74"
  },
  "origin": "70.81.232.143",
  "url": "https://httpbin.org/get"
}