238 lines
5.1 KiB
Markdown
238 lines
5.1 KiB
Markdown
# HTTP Convert
|
|
|
|
A powerful CLI tool and web interface that converts HTTP requests between different formats (cURL, HTTPie, fetch, and axios).
|
|
|
|
## Features
|
|
|
|
- **Bidirectional Format Conversion** - Convert HTTP requests between cURL, HTTPie, fetch, and axios formats
|
|
- **Interactive CLI Mode** - Step-by-step wizard for building HTTP requests
|
|
- **Syntax Highlighting** - Colorized output for better readability
|
|
- **Web Interface** - Browser-based visual request construction tool
|
|
- **Configuration Support** - Store your preferences in a config file
|
|
|
|
## Installation
|
|
|
|
### From Source
|
|
|
|
```bash
|
|
# Clone the repository
|
|
git clone https://github.com/yourusername/http-convert.git
|
|
cd http-convert
|
|
|
|
# Install dependencies
|
|
pip install -e .
|
|
|
|
# Or install with dev dependencies
|
|
pip install -e ".[dev]"
|
|
```
|
|
|
|
### Using pip
|
|
|
|
```bash
|
|
pip install http-convert
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Command Line Interface
|
|
|
|
#### Convert a request
|
|
|
|
```bash
|
|
# Auto-detect input format
|
|
http-convert "curl 'https://api.example.com/users'" --to fetch
|
|
|
|
# Specify input format explicitly
|
|
http-convert "curl 'https://api.example.com/users'" --from curl --to httpie
|
|
```
|
|
|
|
#### Interactive Mode
|
|
|
|
```bash
|
|
http-convert interactive
|
|
```
|
|
|
|
This launches an interactive wizard to build HTTP requests step by step.
|
|
|
|
#### List Supported Formats
|
|
|
|
```bash
|
|
http-convert formats
|
|
```
|
|
|
|
#### Configuration
|
|
|
|
```bash
|
|
# Show current configuration
|
|
http-convert config --show
|
|
|
|
# Set default output format
|
|
http-convert config --set-format httpie
|
|
|
|
# Toggle syntax highlighting
|
|
http-convert config --toggle-highlight
|
|
|
|
# Toggle compact output
|
|
http-convert config --toggle-compact
|
|
|
|
# Reset to defaults
|
|
http-convert config --reset
|
|
```
|
|
|
|
#### Web Interface
|
|
|
|
```bash
|
|
# Start web interface (opens browser automatically)
|
|
http-convert web
|
|
|
|
# Custom host and port
|
|
http-convert web --host 0.0.0.0 --port 8080
|
|
```
|
|
|
|
### Options
|
|
|
|
| Option | Description |
|
|
|--------|-------------|
|
|
| `--from, -f` | Input format (auto-detected if not specified) |
|
|
| `--to, -t` | Output format (required) |
|
|
| `--compact/--no-compact` | Compact output without line breaks |
|
|
| `--highlight/--no-highlight` | Enable/disable syntax highlighting |
|
|
| `--config, -c` | Path to config file |
|
|
|
|
## Supported Formats
|
|
|
|
### cURL
|
|
|
|
```bash
|
|
curl -X POST 'https://api.example.com/users' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"name": "John"}'
|
|
```
|
|
|
|
### HTTPie
|
|
|
|
```bash
|
|
POST https://api.example.com/users \
|
|
Content-Type:application/json \
|
|
'{"name": "John"}'
|
|
```
|
|
|
|
### Fetch
|
|
|
|
```javascript
|
|
fetch('https://api.example.com/users', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({"name": "John"})
|
|
})
|
|
```
|
|
|
|
### Axios
|
|
|
|
```javascript
|
|
axios({
|
|
method: 'POST',
|
|
url: 'https://api.example.com/users',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
"name": "John"
|
|
}
|
|
})
|
|
```
|
|
|
|
## Configuration File
|
|
|
|
The default configuration file is located at `~/.http-convert.yaml`. You can also specify a custom config file using the `--config` option.
|
|
|
|
### Example Configuration
|
|
|
|
```yaml
|
|
default_format: curl
|
|
syntax_highlighting: true
|
|
compact_output: false
|
|
theme: monokai
|
|
```
|
|
|
|
## Interactive Mode
|
|
|
|
The interactive mode guides you through building an HTTP request:
|
|
|
|
1. Select HTTP method (GET, POST, PUT, PATCH, DELETE)
|
|
2. Enter the URL
|
|
3. Optionally add headers
|
|
4. Optionally add query parameters
|
|
5. Optionally add request body
|
|
6. Preview your request
|
|
7. Generate output in your chosen format
|
|
8. Convert to another format if needed
|
|
|
|
## Web Interface
|
|
|
|
The web interface provides:
|
|
|
|
- Visual request builder with form inputs
|
|
- Live preview of generated code
|
|
- Tabbed output for different formats
|
|
- Quick example templates
|
|
- Copy to clipboard functionality
|
|
- Parse existing requests from any supported format
|
|
|
|
## Development
|
|
|
|
### Running Tests
|
|
|
|
```bash
|
|
# Run all tests
|
|
pytest tests/ -v
|
|
|
|
# Run with coverage
|
|
pytest tests/ --cov=src/http_convert
|
|
```
|
|
|
|
### Project Structure
|
|
|
|
```
|
|
http-convert/
|
|
├── src/http_convert/
|
|
│ ├── __init__.py
|
|
│ ├── cli.py # Click CLI commands
|
|
│ ├── models.py # Pydantic models
|
|
│ ├── parsers.py # Format parsers
|
|
│ ├── generators.py # Format generators
|
|
│ ├── highlighter.py # Syntax highlighting
|
|
│ ├── config.py # Configuration management
|
|
│ └── web.py # FastAPI web app
|
|
├── tests/
|
|
│ ├── test_models.py
|
|
│ ├── test_parsers.py
|
|
│ ├── test_generators.py
|
|
│ ├── test_cli.py
|
|
│ └── test_web.py
|
|
├── pyproject.toml
|
|
├── requirements.txt
|
|
└── README.md
|
|
```
|
|
|
|
## Contributing
|
|
|
|
1. Fork the repository
|
|
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
5. Open a Pull Request
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
|
|
## Acknowledgments
|
|
|
|
- [Click](https://click.palletsprojects.com/) - CLI framework
|
|
- [Rich](https://github.com/Textualize/rich) - Terminal formatting
|
|
- [Pydantic](https://pydantic.dev/) - Data validation
|
|
- [FastAPI](https://fastapi.tiangolo.com/) - Web framework
|