Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
axios-curlirize
Advanced tools
Axios third-party module to print all axios requests as curl commands in the console. This repository is forked from axios-curlirize <https://www.npmjs.com/package/axios-curlirize> and supports use with Node JS without having to enable ES6 imports. This r
Weekly downloads
Readme
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.
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.
By default, axios-curlirize uses the console.log/error()
functions. It is possible to change the logger by doing something similar to this:
// when initiating your curlirize instance
curlirize(axios, (result, err) => {
const { command } = result;
if (err) {
// use your logger here
} else {
// use your logger here
}
});
axios-curlirize is super easy to use. First you'll have to install it.
npm i --save axios-curlirize@latest
Then all you have to do is import and instanciate curlirize in your app. Here's a sample:
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);
});
});
To curlirize any other instances of axios (aside from the base one), please call the curlirize()
method on that instance.
const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {'X-Custom-Header': 'foobar'} });
curlirize(instance);
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.
axios
.post('http://localhost:7500/', { dummy: 'data' }, {
curlirize: false
})
.then(res => {
console.log('success');
})
.catch(err => {
console.log(err);
});
axios
.post('http://localhost:7500/', { dummy: 'data' })
.then(res => {
res.config.clearCurl();
})
.catch(err => {
console.log(err);
});
FAQs
Axios third-party module to print all axios requests as curl commands in the console. This repository is forked from axios-curlirize <https://www.npmjs.com/package/axios-curlirize> and supports use with Node JS without having to enable ES6 imports. This r
The npm package axios-curlirize receives a total of 16,142 weekly downloads. As such, axios-curlirize popularity was classified as popular.
We found that axios-curlirize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.