XDiff-NG: HTTP Request Comparison and Building Tools
XDiff-NG is a powerful command-line toolkit for HTTP request comparison and construction, written in Rust. It provides two main utilities:
- xdiff: A sophisticated diff tool for comparing HTTP requests and responses. Perfect for comparing differences between production and staging environments, or different versions of the same API.
- xreq: A flexible HTTP request builder based on predefined profiles. An excellent replacement for curl/httpie when dealing with complex HTTP requests.
Features
- 🔍 Smart HTTP Comparison: Compare requests and responses with configurable skip rules
- 🎨 Syntax Highlighting: Beautiful colored output for better readability
- ⚙️ Flexible Configuration: YAML-based configuration with profile support
- 🚀 High Performance: Built with Rust for speed and reliability
- 📝 Rich Output Formats: Support for various output formats and highlighting
- 🔧 Extensible: Easy to extend with custom profiles and configurations
Installation
From Source
The binaries will be available in target/release/:
xdiff-livexreq-live
Using Cargo
Quick Start
1. Using xdiff
Basic comparison:
# Compare two API endpoints using a predefined profile
# Compare with extra parameters
Interactive mode:
# Parse and compare URLs interactively
# Then input URLs like:
# https://jsonplaceholder.typicode.com/todos/1?a=1&b=2
# https://jsonplaceholder.typicode.com/todos/2?a=2&b=3
# todo
2. Using xreq
Make HTTP requests:
# Execute a request using a predefined profile
# Run with custom parameters
XDiff - HTTP Request Comparison Tool
XDiff allows you to compare HTTP requests and responses between different environments or API versions. It's particularly useful for:
- Comparing production vs staging environments
- Validating API changes between versions
- Debugging differences in HTTP responses
- Testing API compatibility
Configuration
XDiff uses YAML configuration files to define comparison profiles. Each profile contains:
- Request definitions: Two requests to compare (method, URL, headers, parameters, body)
- Response filtering: Rules for skipping certain headers or body fields during comparison
Example configuration:
---
# Profile for comparing Rust website responses
rust:
req1:
method: GET
url: https://www.rust-lang.org/
headers:
user-agent: Aloha
params:
hello: world
req2:
method: GET
url: https://www.rust-lang.org/
params:
res:
skip_headers:
- set-cookie
- date
- via
- x-amz-cf-id
skip_body:
- timestamp
- request_id
# Profile for comparing JSON API responses
todo:
req1:
url: https://jsonplaceholder.typicode.com/todos/1
params:
a: 100
req2:
url: https://jsonplaceholder.typicode.com/todos/2
params:
c: 200
res:
skip_headers:
- report-to
- date
- x-ratelimit-remaining
- x-ratelimit-reset
- cf-ray
- age
skip_body:
- id
Command Line Options
)
)
Extra Parameters
You can override or add parameters using the -e flag:
-e key=value: Add/override query parameter-e @key=value: Add/override header-e #key=value: Add/override body parameter
XReq - HTTP Request Builder
XReq is a powerful HTTP client that builds requests based on predefined profiles. It's designed to replace curl or httpie for complex HTTP requests.
Features
- Profile-based requests: Define reusable request templates
- Parameter substitution: Dynamic parameter injection
- Rich output: Syntax highlighted response display
- Header management: Easy header customization
- Body templating: Support for various body formats
Configuration
---
# API testing profile
api:
method: POST
url: https://api.example.com/users
headers:
content-type: application/json
authorization: Bearer {{token}}
body:
name: "{{name}}"
email: "{{email}}"
# Simple GET request profile
todo:
method: GET
url: https://jsonplaceholder.typicode.com/todos/{{id}}
params:
_limit: 10
Command Line Usage
Configuration File Format
Both tools use YAML configuration files. See yaml.md for detailed YAML syntax reference.
Profile Structure
---
profile_name:
method: GET|POST|PUT|DELETE|PATCH # HTTP method (default: GET)
url: string # Request URL (required)
headers: # Request headers
key: value
params: # Query parameters
key: value
body: # Request body (for POST/PUT/PATCH)
key: value
res: # Response filtering (xdiff only)
skip_headers: # Headers to ignore in comparison
- header-name
skip_body: # Body fields to ignore in comparison
- field-name
Examples
1. Comparing API Endpoints
Compare two different API endpoints:
# Compare todo items from JSONPlaceholder API
2. Environment Comparison
Compare the same endpoint across different environments:
---
api_comparison:
req1:
url: https://staging-api.example.com/users
headers:
authorization: Bearer staging-token
req2:
url: https://prod-api.example.com/users
headers:
authorization: Bearer prod-token
res:
skip_headers:
- date
- server
- x-request-id
3. Version Comparison
Compare different API versions:
# Compare v1 vs v2 API responses
4. Making HTTP Requests with xreq
# Make a simple GET request
# POST request with parameters
Development
Prerequisites
- Rust 1.70 or later
- Cargo
Building
# Debug build
# Release build
# Run tests
# Run with examples
Project Structure
├── src/
│ ├── bin/ # Binary entry points
│ │ ├── xdiff.rs # xdiff CLI
│ │ └── xreq.rs # xreq CLI
│ ├── config/ # Configuration handling
│ ├── cli.rs # Command line interface
│ ├── lib.rs # Library exports
│ └── utils.rs # Utility functions
├── examples/ # Example code
├── fixtures/ # Test configuration files
├── tests/ # Integration tests
└── README.md # This file
Running Tests
# Run all tests
# Run specific test
# Run with verbose output
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Rust
- HTTP client powered by reqwest
- Text diffing by similar
- Syntax highlighting by syntect
- CLI framework by clap
Changelog
v0.1.0
- Initial release
- Basic xdiff functionality for HTTP request comparison
- xreq tool for making HTTP requests from profiles
- YAML configuration support
- Syntax highlighting for output
- Interactive parsing mode