# curl-cmd

> Generate a curl command line argument list from an http request object

Latest version **0.0.1** (published 2015-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install curl-cmd
pnpm add curl-cmd
yarn add curl-cmd
bun add curl-cmd
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2015-05-19 |
| First published | 2013-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Dave Eddy |
| Maintainers | bahamas10 |

## Links

- npm: https://www.npmjs.com/package/curl-cmd
- Repository: https://github.com/bahamas10/node-curl-cmd
- Issues: https://github.com/bahamas10/node-curl-cmd/issues
- npm.io page: https://npm.io/package/curl-cmd

## Dependencies (1)

- [shell-escape](https://npm.io/package/shell-escape.md) 0.2.0

## Recent versions

- 0.0.1 (latest) — 2015-05-19
- 0.0.0 — 2013-06-06

## README

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](http://nodejs.org) example for an HTTP get request

``` js
var http = require('http');
var curl = require('curl-cmd');

var options = {
  hostname: 'ifconfig.me',
  port: 80,
  path: '/ip',
  method: 'GET'
};

console.log('=> %s', curl.cmd(options));

http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
}).end();
```

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

``` js
> var curl = require('curl-cmd')
undefined

> curl.cmd('http://www.daveeddy.com/something')
'curl -X GET http://www.daveeddy.com/something'

> curl.cmd({host: 'daveeddy.com', port: 8080, method: 'DELETE', path: '/data/something'})
'curl -X DELETE http://daveeddy.com:8080/data/something'

> curl.cmd({host: 'daveeddy.com', port: 8080, method: 'DELETE', path: '/data/something', headers: { 'User-Agent': 'Internet Explorer'} })
'curl -X DELETE -H \'User-Agent: Internet Explorer\' http://daveeddy.com:8080/data/something'

> curl.cmd({host: 'daveeddy.com', port: 8080, method: 'DELETE', path: '/data/something', headers: { 'User-Agent': 'Internet Explorer'}, auth: 'dave:secret' })
'curl -X DELETE -u dave:secret -H \'User-Agent: Internet Explorer\' http://daveeddy.com:8080/data/something'

> curl.cmd({host: 'daveeddy.com', port: 8080, method: 'PUT', path: '/data/something', headers: { 'User-Agent': 'Internet Explorer'}, auth: 'dave:secret' }, {ssl: true, verbose: true})
'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 to `true` to use HTTPS instead of HTTP, defaults to `false`
- `curlopts.verbose`: set to `true` to add `-v` to the curl command, defaults to `false`
- `curlopts.headers`: set to `true` to add `-i` to the curl command, defaults to `false`
- `curlopts.options`: an optional array of arguments to add to the curl command, defaults to `[]`

License
-------

MIT

---
_Source: https://npm.io/package/curl-cmd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
