Feature request: generate curl command with quotes instead of backslashes
jjnilton opened this issue · 3 comments
jjnilton commented
Request block:
POST https://example.com
Content-Type: application/json
{
"order_ref": "12321312",
"total": 123,
"items": [
{
"item_title": "Payment Test in Digital Wallet",
"unit_price": 123,
"quantity": 1
}
],
"buyer": {
"name": "Foo bar",
"personId": "123",
"phone": "123"
},
"callback_url": "https:\/\/example.com\/example\/example\/v1\/example\/example\/example\/123"
}
Current curl command from the block above:
curl -i -H Content-Type\:\ application/json -XPOST https\://example.com -d \{'
'\ \ \ \ \"order_ref\"\:\ \"12321312\"\,'
'\ \ \ \ \"total\"\:\ 123\,'
'\ \ \ \ \"items\"\:\ \['
'\ \ \ \ \ \ \ \ \{'
'\ \ \ \ \ \ \ \ \ \ \ \ \"item_title\"\:\ \"Payment\ Test\ in\ Digital\ Wallet\"\,'
'\ \ \ \ \ \ \ \ \ \ \ \ \"unit_price\"\:\ 123\,'
'\ \ \ \ \ \ \ \ \ \ \ \ \"quantity\"\:\ 1'
'\ \ \ \ \ \ \ \ \}'
'\ \ \ \ \]\,'
'\ \ \ \ \"buyer\"\:\ \{'
'\ \ \ \ \ \ \ \ \"name\"\:\ \"Foo\ bar\"\,\ '
'\ \ \ \ \ \ \ \ \"personId\"\:\ \"123\"\,'
'\ \ \ \ \ \ \ \ \"phone\"\:\ \"123\"'
'\ \ \ \ \}\,'
'\ \ \ \ \"callback_url\"\:\ \"https\:\\/\\/example.com\\/example\\/example\\/v1\\/example\\/example\\/example\\/123\"'
'\}'
'
Suggested curl command output:
curl -i -H "Content-Type: application/json" -XPOST https://example.com -d '{
"order_ref": "12321312",
"total": 123,
"items": [
{
"item_title": "Payment Test in Digital Wallet",
"unit_price": 123,
"quantity": 1
}
],
"buyer": {
"name": "Foo bar",
"personId": "123",
"phone": "123"
},
"callback_url": "https://example.com/example/example/v1/example/example/example/123"
}'
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.
failable commented
+1
ccarlile commented
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.")))))