# axios-curlirize

> Axios third-party module to print all axios requests as curl commands in the console. This repository is forked from axios-curlirize and supports use with Node JS without having to enable ES6 imports. This r

Latest version **2.0.0** (published 2021-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install axios-curlirize
pnpm add axios-curlirize
yarn add axios-curlirize
bun add axios-curlirize
```

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-10-22 |
| First published | 2018-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/axios-curlirize) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 30.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 191 |
| Author | delirius325 |
| Maintainers | delirius325 |
| Keywords | axios, curl, debug |

## Links

- npm: https://www.npmjs.com/package/axios-curlirize
- Repository: https://github.com/delirius325/axios-curlirize
- Homepage: https://github.com/delirius325/axios-curlirize#readme
- Issues: https://github.com/delirius325/axios-curlirize/issues
- npm.io page: https://npm.io/package/axios-curlirize

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2021-10-22
- 1.4.0 — 2021-06-30
- 1.3.7 — 2020-09-23
- 1.3.6 — 2020-09-23
- 1.3.5 — 2020-03-24
- 1.3.4 — 2019-10-22
- 1.3.3 — 2019-10-10
- 1.3.2 — 2019-10-09
- 1.3.1 — 2019-08-26
- 1.3.0 — 2019-08-26
- 1.2.3 — 2019-08-26
- 1.2.2 — 2019-08-26
- 1.2.1 — 2019-07-02
- 1.2.0 — 2019-05-14
- 1.1.0 — 2019-03-01
- … 7 more at https://npm.io/package/axios-curlirize/versions

## README

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7d519058c2f340428a1b7ef22d71368f)](https://app.codacy.com/app/antho325/axios-curlirize?utm_source=github.com&utm_medium=referral&utm_content=delirius325/axios-curlirize&utm_campaign=Badge_Grade_Dashboard)
[![CircleCI](https://circleci.com/gh/delirius325/axios-curlirize.svg?style=svg)](https://circleci.com/gh/delirius325/axios-curlirize)
[![npm version](https://badge.fury.io/js/axios-curlirize.svg)](https://badge.fury.io/js/axios-curlirize)

# Description

This module is an axios third-party module to log any axios request as a curl command in the console. It was originally posted as a suggestion on the axios repository, but since we believed it wasn't in the scope of axios to release such feature, we decided to make it as an independent module.

# How it works

The module makes use of axios' interceptors to log the request as a cURL command. It also stores it in the response's config object. Therefore, the command can be seen in the app's console, as well as in the `res.config.curlCommand` property of the response.

# Changing the logger

By default, axios-curlirize uses the `console.log/error()` functions. It is possible to change the logger by doing something similar to this:

```javascript
// when initiating your curlirize instance
curlirize(axios, (result, err) => {
  const { command } = result;
  if (err) {
    // use your logger here
  } else {
    // use your logger here
  }
});
```

# How to use it

axios-curlirize is super easy to use. First you'll have to install it.

```shell
npm i --save axios-curlirize@latest
```

Then all you have to do is import and instanciate curlirize in your app. Here's a sample:

```javascript
import axios from 'axios';
import express from 'express';
import curlirize from 'axios-curlirize';

const app = express();

// initializing axios-curlirize with your axios instance
curlirize(axios);

// creating dummy route
app.post('/', (req, res) => {
  res.send({ hello: 'world!' });
});

// starting server
app.listen(7500, () => {
  console.log('Dummy server started on port 7500');
  /*
             The output of this in the console will be :
             curl -X POST -H "Content-Type:application/x-www-form-urlencoded" --data {"dummy":"data"} http://localhost:7500/
        */
  axios
    .post('http://localhost:7500/', { dummy: 'data' })
    .then(res => {
      console.log('success');
    })
    .catch(err => {
      console.log(err);
    });
});
```

## Curilirize additional axios instance
To curlirize any other instances of axios (aside from the base one), please call the `curlirize()` method on that instance.
```javascript
const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {'X-Custom-Header': 'foobar'} });
curlirize(instance);
```

# Disable the logger

By default, all requests will be logged. But you can disable this behaviour unitarily by setting the `curlirize` option to false within the axios request.

```javascript
axios
  .post('http://localhost:7500/', { dummy: 'data' }, {
    curlirize: false
  })
  .then(res => {
    console.log('success');
  })
  .catch(err => {
    console.log(err);
  });
```

# Clear a request

```javascript
axios
  .post('http://localhost:7500/', { dummy: 'data' })
  .then(res => {
    res.config.clearCurl();
  })
  .catch(err => {
    console.log(err);
  });
```

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