curl-cmd
Generate a curl command line argument list from an http request object
Install
npm install curl-cmd
Example
Taken from the Node.JS example for an HTTP get request
var http = ;var curl = ;var options =hostname: 'ifconfig.me'port: 80path: '/ip'method: 'GET';console;http;
The line curl.cmd(options)
is the interesting part as that will generate
the curl command seen in the output
=> curl -X GET http://ifconfig.me:80/ip
STATUS: 200
HEADERS: {"date":"Thu, 06 Jun 2013 16:56:30 GMT","server":"Apache","vary":"Accept-Encoding","connection":"close","transfer-encoding":"chunked","content-type":"text/plain"}
BODY: 8.8.8.8
Simple Example
> var curl =undefined> curl'curl -X GET http://www.daveeddy.com/something'> curl'curl -X DELETE http://daveeddy.com:8080/data/something'> curl'curl -X DELETE -H \'User-Agent: Internet Explorer\' http://daveeddy.com:8080/data/something'> curl'curl -X DELETE -u dave:secret -H \'User-Agent: Internet Explorer\' http://daveeddy.com:8080/data/something'> curl'curl -X PUT -u dave:secret -H \'User-Agent: Internet Explorer\' -v https://daveeddy.com:8080/data/something'
Usage
Pass in a URI as a string, a url.parsed()
object, or an object suitable for
making an HTTP request as the first argument to get the curl command.
curl.cmd(options, curlopts={})
This returns a stringified curl command suitable for running on the shell
curl.args(options, curlopts={})
Same as above, except returns an array of separate arguments to use for the curl command
curlopts
The optional second argument is used to pass options to curl
curlopts.ssl
: set totrue
to use HTTPS instead of HTTP, defaults tofalse
curlopts.verbose
: set totrue
to add-v
to the curl command, defaults tofalse
curlopts.headers
: set totrue
to add-i
to the curl command, defaults tofalse
curlopts.options
: an optional array of arguments to add to the curl command, defaults to[]
License
MIT