Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/megatolya/format-curl
Create curl string from request params
https://github.com/megatolya/format-curl
curl formatting
Last synced: about 1 month ago
JSON representation
Create curl string from request params
- Host: GitHub
- URL: https://github.com/megatolya/format-curl
- Owner: megatolya
- Created: 2018-02-01T14:54:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-31T17:48:35.000Z (about 6 years ago)
- Last Synced: 2024-04-14T07:17:56.362Z (9 months ago)
- Topics: curl, formatting
- Language: JavaScript
- Homepage:
- Size: 73.2 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# format-curl
Format curl execution from request params## Installation
from npm```shell
npm install --save format-curl
```from unpkg
```html
const curl = window.formatCurl({
href: 'http://my-host/pathname/',
},
{
args: ['-v'],
headers: {
'accept': '*/*',
},
});console.log(curl);
```
## Usage
```js
import curl from 'format-curl';const url = 'https://myhost.com?param=value';
const options = {
headers: {
'x-header': 'test',
'x-header2': 'test2'
},
body: JSON.stringify({
param: '123'
}),
method: 'PUT',
args: ['-vvv']
};console.log(curl(url, options));
// curl -vvv "https://myhost.com?param=value" -H "x-header: test" -H "x-header2: test2" --data '{"param":"123"}' -X PUT
```See `test/index.test.js` for more examples!
### API
#### curl(url, [options])
Returns a string with a resulting curl command.
##### url
Type: `string` `Object`The URL to request, as a string, a [WHATWG URL](https://nodejs.org/api/url.html#url_class_url) or [https.request options](https://nodejs.org/api/https.html#https_https_request_options_callback).
In case you provide partial or empty url it will use base url `http://localhost/` to fullfil it.
##### options
Type: `Object`###### headers
Type: `Object`Request headers.
###### json
Type: `boolean`Helper for json format specific headers. Adds `accept` and `content-type` headers with `application/json` value in case they aren't presented.
###### method
Type: `string`Request method.
###### body
Type: `string` `Object`Request body. If you provide an object, it will be serialized via `JSON.stringify`.
###### args
Type: `Array`Curl arguments. Like `-vvv`, `-k`, `-L` and etc.
## Publish
Build package and publish under `beta` tag:
```bash
npm run build && npm publish --tag beta
```Now you can install it using published version (`npm install format-curl@`) and test it. When you finish, add a `latest` tag to the published version:
```bash
npm dist-tag rm format-curl beta
npm dist-tag add format-curl@ latest
```## TODO
* user-argent, cookies as a params (and as curl arguments)