Files
schema2mock/http_log_explorer/README.md

161 lines
3.8 KiB
Markdown

# HTTP Log Explorer
A powerful CLI tool for parsing, exploring, and analyzing HTTP traffic logs from HAR files, curl -v output, and Chrome DevTools network exports.
## Features
- **Multi-format parsing**: HAR files, curl -v verbose output, and Chrome DevTools network exports
- **Interactive CLI**: Rich terminal UI with beautifully formatted tables
- **Advanced filtering**: Filter by method, status code, URL pattern, content type
- **Request/Response diffing**: Side-by-side comparison of HTTP pairs
- **API analytics**: Endpoint frequency, method distribution, status code breakdown, response time statistics
- **OpenAPI generation**: Automatically generate OpenAPI 3.0 specs from observed traffic
- **Export capabilities**: JSON, cURL commands, Python/JavaScript/Go code snippets
## Installation
### From Source
```bash
pip install -e .
```
### Dependencies
```
click==8.1.7
rich==13.7.0
haralyzer==2.0.0
pytest==8.0.0
openapi-spec-validator==0.7.1
```
## Quick Start
```bash
# Load a HAR file and show statistics
http-log-explorer load access.har --stats
# List entries with filters
http-log-explorer list-entries --method GET --status 200
# Search across URLs and bodies
http-log-explorer search "api/users"
# Compare two requests
http-log-explorer diff entry-1 entry-2
# Export to OpenAPI spec
http-log-explorer export-openapi api-spec.json --title "My API"
# Export as cURL commands
http-log-explorer export-curl commands.sh
# Export as Python code
http-log-explorer export-code client.py --language python
```
## Commands
| Command | Description |
|---------|-------------|
| `load FILE` | Load and parse an HTTP log file |
| `list-entries` | List entries with optional filtering |
| `search QUERY` | Search across URLs and bodies |
| `diff ID1 ID2` | Compare two entries by ID |
| `stats` | Show traffic statistics |
| `filter-entries` | Filter entries and show results |
| `export-json FILE` | Export entries to JSON |
| `export-curl FILE` | Export as cURL commands |
| `export-code FILE` | Export as code snippets |
| `export-openapi FILE` | Generate OpenAPI spec |
## Filtering Options
```bash
# Filter by HTTP method
http-log-explorer list-entries --method GET --method POST
# Filter by status code
http-log-explorer list-entries --status 200 --status 404
# Filter by URL pattern (regex)
http-log-explorer list-entries --url "/api/users"
# Filter by content type
http-log-explorer list-entries --content-type application/json
```
## Supported Formats
### HAR Files (HTTP Archive)
Export from browser DevTools or capture with tools like Wireshark.
### curl -v Output
Paste output from `curl -v` or `curl --verbose`.
### Chrome DevTools Network Export
Export network requests from Chrome DevTools.
## Configuration
### Environment Variables
- `HTTP_LOG_DEBUG=true` - Enable verbose output
## Examples
### Analyzing API Traffic
```bash
# Load traffic data
http-log-explorer load api_traffic.har
# See overall statistics
http-log-explorer stats
# Find all 4xx errors
http-log-explorer list-entries --status 404 --status 400
# Search for specific endpoints
http-log-explorer search "/users"
```
### Generating API Documentation
```bash
# Load traffic and export OpenAPI spec
http-log-explorer load api.har
http-log-explorer export-openapi openapi.json --title "User API" --version "2.0"
```
### Exporting to Code
```bash
# Export as Python requests
http-log-explorer load api.har
http-log-explorer export-code client.py --language python
# Export as JavaScript/Node.js
http-log-explorer export-code client.js --language javascript
# Export as Go
http-log-explorer export-code client.go --language go
```
## License
MIT License - see LICENSE file for details
## Contributing
Contributions welcome! Please ensure tests pass before submitting PRs.
```bash
pytest tests/ -v
ruff check http_log_explorer/
```