New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

curl2axios

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

curl2axios

This lib provide a interceptor to generate a curl from axios request

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

curl2axios

Overview

curl2axios is a lightweight Axios interceptor for generating cURL commands from Axios requests. It simplifies the process of converting your Axios requests into cURL commands for easier debugging and sharing.


Installation

Install the library using npm or yarn:


npm install curl2axios


OR


yarn add curl2axios


Usage

Basic Usage


import axios from 'axios';
import { curlInterceptor } from 'curl2axios';

axios.interceptors.request.use(curlInterceptor);

axios.get('https://api.com/item/1');


This will automatically generate a cURL command in the console based on the Axios request.


{
  occurredAt: '2024-02-02T22:17:45.514Z',
  curlCommand: "curl 'https://api.com/item/1' -X GET -H 'Accept: application/json, text/plain, */*' -H 'Content-Type: '"
}


Custom Callback You can also provide a custom callback function to handle the generated cURL command. This is useful if you want to do something specific with the command, such as logging it in a different way.


import axios from 'axios';
import { curlInterceptor } from 'curl2axios';

const myCallback = (curl: string) => console.log(curl);

axios.interceptors.request.use((req) => curlInterceptor(req, myCallback));

axios.get('https://api.com/item/1');


In this example, the custom callback function myCallback will be called with the generated cURL command.

Example Output

For the given Axios request:


axios.get('https://api.com/item/1');

// curl 'https://api.com/item/1' -X GET -H 'Accept: application/json, text/plain, */*' -H 'Content-Type: '


Bind


import axios from 'axios';
import { bindCurl } from 'curl2axios';

const instance = bindCurl(axios.create({ baseURL: 'https://pokeapi.co/api/v2' }));

await instance.get('/berry-flavor/1');

console.log(instance.curl);

// > "curl '/berry-flavor/1' -X GET -H 'Accept: application/json, text/plain, */*' -H 'Content-Type: ' --url 'https://pokeapi.co/api/v2'"

License

axios2curl is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Package last updated on 14 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc