curl-string
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

request -> cURL string

Debug API calls by printing human-readable cURL strings

Motivation

  • cURL 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

Usage

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

Advanced Usage

curlString supports an optional 3rd parameter config object:

const curlStringOptions = { colorJson: true, jsonIndentWidth: 2}; // (these are the defaults)
const str = curlString(url, options, curlStringOptions);

Versions

3.0.x

Converted to ESM (import instead of require).

2.x.x

Use this version if you still need require syntax (CommonJS).

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.1.043latest

Version History

VersionDownloads (Last 7 Days)Published
3.1.043
3.0.00
2.0.028
1.1.1391
1.1.037
1.0.00

Package Sidebar

Install

npm i curl-string

Weekly Downloads

499

Version

3.1.0

License

MIT

Unpacked Size

11.3 kB

Total Files

6

Last publish

Collaborators

  • zvakanaka