Skip to content
Convert cURL command to Emacs Lisp code
Emacs Lisp
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Run tests in ci Mar 5, 2020
.gitignore Initial commit Mar 5, 2020
LICENSE.md Add LICENSE.md Mar 8, 2020
README.md Add Melpa badge Mar 22, 2020
curl-to-elisp-tests.el Map -s/--silent to url-show-status Mar 21, 2020
curl-to-elisp.el Map -s/--silent to url-show-status Mar 21, 2020

README.md

Convert cURL command to Emacs Lisp code

Melpa

Inspired by curl-to-Go: Convert curl commands to Go code.

(curl-to-elisp "curl example.com")
;; =>
(url-retrieve-synchronously "http://example.com")

(curl-to-elisp "curl -d 'hello world' example.com")
;; =>
(let ((url-request-method "POST")
      (url-request-extra-headers
       '(("Content-Type" . "application/x-www-form-urlencoded")))
      (url-request-data "hello world"))
  (url-retrieve-synchronously "http://example.com"))

To get started, try M-x curl-to-elisp curl -I example.com, the Emacs Lisp code will be pretty-printed in echo area.

Supported curl options

The following options are supported, other options are ignored.

Option Note
-H, --header <header>
-I, --head
-X, --request <command>
-d, --data <data> does not interpret @ as file
--data-ascii <data>
--data-binary <data>
--data-raw <data>
--data-urlencode <data>
-F, --form <name=content> does not interpret @ as file
--form-string <name=string>
-A, --user-agent <name>
-e, --referer <URL>
--url <url>
-u, --user <user:password> does not prompt for a password
-s, --silent

-L, --location

Regarding the location header, curl doesn't redirect unless you use -L, --location, however, url-retrieve[-synchronously] DOES automatically redirect, to inhibit redirection, let-binding url-max-redirections, e.g.,

(let ((url-max-redirections 0))
  (display-buffer
   (url-retrieve-synchronously "http://emacs-china.org")))

Dependencies

  • Emacs 25.1
You can’t perform that action at this time.