Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zvakanaka/curl-string
Debug requests by printing human-readable cURL strings
https://github.com/zvakanaka/curl-string
curl javascript node
Last synced: 3 days ago
JSON representation
Debug requests by printing human-readable cURL strings
- Host: GitHub
- URL: https://github.com/zvakanaka/curl-string
- Owner: zvakanaka
- Created: 2019-08-13T19:03:42.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-17T20:06:30.000Z (over 1 year ago)
- Last Synced: 2024-09-24T11:36:54.051Z (about 1 month ago)
- Topics: curl, javascript, node
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/curl-string
- Size: 225 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# request -> cURL string
Debug API calls by printing human-readable cURL strings## Motivation
- [cURL](https://curl.haxx.se/) is the most well-known command line tool for API calls
- Logging cURL commands to the console helps debug API calls
- cURL commands are easy to read (when printed in human readable format)
- cURL commands can be pasted into a terminal or [Postman](https://learning.getpostman.com/docs/postman/collections/data_formats/#importing-postman-data)## Usage
```js
import curlString from 'curl-string';
const debug = true;const url = 'http://example.com';
const options = {
method: 'post',
headers: { accept: 'application/json', 'accept-language': 'en' },
body: { hello: 'world' }
};if (debug) {
console.log(curlString(url, options));
}
// make real call here, e.g. fetch(url, options);
```
Output:
![screenshot](https://imgur.com/FRlmfLR.png)### Advanced Usage
`curlString` supports an optional 3rd parameter config object:
```js
const curlStringOptions = { colorJson: true, jsonIndentWidth: 2}; // (these are the defaults)
const str = curlString(url, options, curlStringOptions);
```## Versions
### 3.x.x and Above
Converted to [ESM](https://github.com/sindresorhus/meta/discussions/15) (`import` instead of `require`).
### 2.x.x and Below
Use this version if you still need `require` syntax (CommonJS).