Skip to content

Used to test modules http request with requests, httpx and http.client

License

Notifications You must be signed in to change notification settings

renanclemonini/http_client_cli_tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HTTP Client CLI Tool πŸš€

A command-line interface tool for testing and comparing different HTTP client libraries in Python. Compare the behavior of http.client, requests, and httpx side-by-side.

πŸ“‹ Features

  • Multiple HTTP Clients: Test with http.client (standard library), requests, and httpx
  • All HTTP Methods: Support for GET, POST, PUT, and PATCH
  • Batch Testing: Test all clients at once with a single command
  • Individual Testing: Test specific clients with specific HTTP methods
  • Verbose Mode: Detailed logging for debugging
  • Configurable Delays: Prevent rate limiting with adjustable delays between requests
  • Clean Architecture: Object-oriented design with abstract base classes
  • Type Hints: Full type annotation support for better IDE integration

πŸ› οΈ Requirements

  • Python 3.7+
  • Dependencies:
    • requests
    • httpx

πŸ“¦ Installation

  1. Clone the repository:
git clone https://github.com/renanclemonini/http_client_cli_tool.git
cd http_client_cli_tool
  1. Create and activate virtual environment:

Windows:

python -m venv .venv
.venv\Scripts\activate

Linux/Mac:

python -m venv .venv
source .venv/bin/activate
  1. Install dependencies:
pip install -r requiments.txt

Note: After create virtual environment you can navigate to folder and execute file directly without environment activate

πŸš€ Usage

Test All Clients

POST Request (all clients):

py main.py test-all-post \
  --location 'https://api.example.com/endpoint' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer token' \
  --data '{"key": "value"}'

GET Request (all clients):

py main.py test-all-get \
  --location 'https://api.github.com/users/github' \
  --header 'Accept: application/json'

PUT Request (all clients):

py main.py test-all-put \
  --location 'https://api.example.com/users/123' \
  --header 'Content-Type: application/json' \
  --data '{"name": "Updated Name"}'

Test Specific Client

Using http.client:

py main.py http \
  --request POST \
  --location 'https://api.example.com/endpoint' \
  --header 'Content-Type: application/json' \
  --data '{"key": "value"}'

Using requests:

py main.py requests \
  --request GET \
  --location 'https://api.example.com/endpoint'

Using httpx:

py main.py httpx \
  --request PUT \
  --location 'https://api.example.com/endpoint' \
  --data '{"key": "value"}'

Using httpx without SSL verification:

py main.py httpx2 \
  --request POST \
  --location 'https://self-signed-cert.example.com/endpoint' \
  --data '{"key": "value"}'

Options

Option Alias Description Default
--location -L Request URL (required) -
--request -X HTTP method (GET, POST, PUT, PATCH) -
--header -H Header in format "Key: Value" (repeatable) -
--data -d JSON data to send -
--verbose -v Show detailed request information false
--delay - Delay in seconds between requests 2.0

Examples

Basic POST request to validate CNPJ:

py main.py test-all-post \
  --location 'https://doc-validation.fashiongirl.com.br/validar_cnpj_cpf' \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: your-api-key' \
  --data '{"documento": "52781445000150"}'

GET request with verbose output:

py main.py test-all-get \
  --verbose \
  --location 'https://api.github.com/repos/python/cpython'

Test single client with custom delay:

py main.py requests \
  --request GET \
  --location 'https://api.example.com/endpoint' \
  --delay 5.0

πŸ“ Project Structure

http-client-cli/
β”œβ”€β”€ http_clients.py      # HTTP client implementations
β”‚   β”œβ”€β”€ HTTPClient       # Abstract base class
β”‚   β”œβ”€β”€ HttpClientLib    # http.client implementation
β”‚   β”œβ”€β”€ RequestsClient   # requests implementation
β”‚   β”œβ”€β”€ HttpxClient      # httpx implementation
β”‚   └── HTTPTester       # Testing orchestrator
β”œβ”€β”€ main.py              # CLI entry point
β”œβ”€β”€ README.md            # This file
└── .venv/               # Virtual environment

πŸ—οΈ Architecture

Class Hierarchy

HTTPClient (ABC)
β”œβ”€β”€ HttpClientLib
β”œβ”€β”€ RequestsClient
└── HttpxClient

HTTPTester
β”œβ”€β”€ test_single_client()
β”œβ”€β”€ test_all_clients()
β”œβ”€β”€ test_all_post()
β”œβ”€β”€ test_all_get()
β”œβ”€β”€ test_all_put()
└── print_summary()

Key Components

  • HTTPClient: Abstract base class defining the interface for all HTTP clients
  • HttpClientLib: Implementation using Python's standard library http.client
  • RequestsClient: Implementation using the popular requests library
  • HttpxClient: Implementation using the modern httpx library
  • HTTPTester: Orchestrates testing across multiple clients with timing and reporting

πŸ“Š Output Example

πŸ§ͺ Testing all clients with POST method...

======================================================================

======================================================================
πŸ” Client: http.client
======================================================================
βœ… Success with http.client!

{
  "status": "success",
  "message": "Request completed successfully"
}

⏳ Waiting 2.0 seconds before next request...

======================================================================
πŸ” Client: requests
======================================================================
❌ Failed with requests
Error: Connection aborted

======================================================================
πŸ” Client: httpx
======================================================================
βœ… Success with httpx!

{
  "status": "success",
  "message": "Request completed successfully"
}

======================================================================
πŸ“Š TEST SUMMARY
======================================================================
βœ… Success   - http.client
❌ Failed    - requests
βœ… Success   - httpx

πŸ“ˆ Success rate: 2/3

πŸ› Troubleshooting

SSL/TLS Errors

If you encounter SSL errors with requests or httpx but http.client works:

  1. The server may have a self-signed certificate
  2. The server may use an old TLS version
  3. Try using httpx2 (no SSL verification):
py main.py httpx2 --request POST --location 'https://...' --data '{...}'

Connection Reset Errors (WinError 10054)

This intermittent error can occur due to:

  • Rate limiting on the server
  • Keep-alive connection issues
  • Server load

Solutions:

  • Increase delay between requests: --delay 5.0
  • Use http.client which has simpler connection handling
  • Test individual clients instead of all at once

Rate Limiting

If testing all clients triggers rate limits:

# Increase delay to 5 seconds
py main.py test-all-post --delay 5.0 --location '...' --data '{...}'

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

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

πŸ™ Acknowledgments

  • Built to debug and compare SSL/TLS behavior across different HTTP client libraries
  • Inspired by real-world API integration challenges
  • Special thanks to the maintainers of requests and httpx

πŸ“§ Contact

Renan Clemonini - +55 71 996 333 313

Project Link: https://github.com/renanclemonini/http_client_cli_tool


⭐ If this project helped you, please consider giving it a star!

About

Used to test modules http request with requests, httpx and http.client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages