Open jjnilton opened 1 year ago
+1
I have this in my init.el to do exactly that:
(defun mine-restclient-copy-curl-command ()
"Formats the request as a curl command and copies the command to the clipboard."
(interactive)
(restclient-http-parse-current-and-do
'(lambda (method url headers entity)
(let* ((header-args
(apply 'append
(mapcar (lambda (header)
(list "-H" (format "\"%s: %s\"" (car header) (cdr header))))
headers)))
(header-parsed (mapconcat 'identity header-args " "))
(method-arg (concat "-X" " " method))
(entity-arg (if (> 0 (string-width entity)) ""
(format "-d \x27%s\x27" entity)))
(curl-command (format "curl %s %s %s %s" header-parsed method-arg url entity-arg)))
(kill-new curl-command)
(message "curl command copied to clipboard.")))))
@ccarlile That's cool! Works like a charm.
Request block:
Current curl command from the block above:
Suggested curl command output:
I'm not sure of the drawback, but the benefit is that it would a bit cleaner, so it would be easier to read/edit.