Files
curl-converter-cli/README.md

2.8 KiB

curl-converter-cli

A powerful CLI tool that converts curl commands into code snippets in multiple programming languages.

Features

  • Convert curl commands to Python, JavaScript, Go, Ruby, and PHP
  • Parse and extract URL, HTTP method, headers, body data, authentication, cookies
  • Support for Basic Auth, Bearer Token, and API Key authentication
  • Handle JSON and form data automatically
  • Interactive CLI mode for pasting curl commands
  • Output to file or stdout

Installation

# Clone the repository
git clone https://github.com/yourusername/curl-converter-cli.git
cd curl-converter-cli

# Install in development mode
pip install -e .

# Or install with dev dependencies
pip install -e ".[dev]"

Usage

Convert curl to Python

curlconverter convert -c "curl -X POST https://api.example.com/data -d '{\"key\":\"value\"}'" -l python

Convert curl to JavaScript

curlconverter convert -c "curl -H 'Authorization: Bearer token' https://api.example.com" -l javascript

Convert curl to Go

curlconverter convert -c "curl -X POST -d 'name=test' https://api.example.com/users" -l go

Convert curl to Ruby

curlconverter convert -c "curl -u user:pass https://api.example.com" -l ruby

Convert curl to PHP

curlconverter convert -c "curl -H 'Content-Type: application/json' https://api.example.com" -l php

Interactive Mode

curlconverter convert -i

List Supported Languages

curlconverter languages

Output:

python       - Python (requests)
javascript   - JavaScript (fetch)
go           - Go (net/http)
ruby         - Ruby (Net::HTTP)
php          - PHP (cURL)

Analyze a curl Command

curlconverter analyze -c "curl https://example.com"

Output:

Parsed curl command:
  URL: https://example.com
  Method: GET

Output to File

curlconverter convert -c "curl https://api.example.com" -l python -o output.py

Supported Languages

Language Library/Module Description
python requests Python HTTP library
javascript fetch Native Fetch API
go net/http Go standard library
ruby Net::HTTP Ruby standard library
php cURL PHP extension

Supported curl Options

  • -X, --request - HTTP method
  • -H, --header - Custom headers
  • -d, --data - Request body data
  • --data-raw - Request body data (raw)
  • -u, --user - Basic authentication
  • -b, --cookie - Cookies
  • -A, --user-agent - User-Agent header
  • -L, --location - Follow redirects
  • -s, --silent - Silent mode

Development

Run Tests

pytest tests/ -v

Run Tests with Coverage

pytest tests/ -v --cov=curlconverter --cov-report=html

License

MIT License - see LICENSE file for details.