A lightweight Python HTTP server that echoes back the HTTP method used in requests. Perfect for testing, debugging, and understanding HTTP request methods.
Echo is a simple HTTP server built with Python's standard library that responds with the HTTP method used in each request (GET, POST, PUT, DELETE, PATCH, etc.). It's an invaluable tool for:
- Testing REST API clients
- Learning about HTTP methods
- Debugging HTTP requests
- Validating request method handling
- Teaching HTTP fundamentals
- Integration testing with mock endpoints
- Method Echo: Returns clear confirmation of the HTTP method used
- Lightweight: Uses only Python's standard library - no external dependencies
- Logging: Built-in request logging to track all incoming requests
- Docker Support: Includes Dockerfile for easy containerization
- Comprehensive: Supports GET, POST, PUT, DELETE, PATCH, HEAD, and OPTIONS methods
- Simple: Minimal setup, just run and test
- Python 3.12+ (or Python 3.x)
- No external dependencies required
git clone https://github.com/regisftm/echo.git
cd echocd app
python app.pyThe server will start on port 80 by default. If you need to run on a different port, you can modify the port parameter in app.py.
Edit app/app.py and change the last line:
if __name__ == '__main__':
run(port=8080) # Change 80 to your desired portdocker build -t echo-server .docker run -p 8080:80 echo-serverThis maps port 80 inside the container to port 8080 on your host machine.
# GET request
curl http://localhost:80/
# Response: Request HTTP Method: GET
# POST request
curl -X POST http://localhost:80/
# Response: Request HTTP Method: POST
# PUT request
curl -X PUT http://localhost:80/
# Response: Request HTTP Method: PUT
# DELETE request
curl -X DELETE http://localhost:80/
# Response: Request HTTP Method: DELETE
# PATCH request
curl -X PATCH http://localhost:80/
# Response: Request HTTP Method: PATCH
# HEAD request (no body returned)
curl -I http://localhost:80/
# OPTIONS request (shows allowed methods)
curl -X OPTIONS http://localhost:80/# GET request
http GET localhost:80
# POST request
http POST localhost:80
# PUT request
http PUT localhost:80import requests
# GET request
response = requests.get('http://localhost:80')
print(response.text) # Output: Request HTTP Method: GET
# POST request
response = requests.post('http://localhost:80')
print(response.text) # Output: Request HTTP Method: POST
# PUT request
response = requests.put('http://localhost:80')
print(response.text) # Output: Request HTTP Method: PUT// GET request
fetch('http://localhost:80')
.then(response => response.text())
.then(data => console.log(data));
// Output: Request HTTP Method: GET
// POST request
fetch('http://localhost:80', {
method: 'POST'
})
.then(response => response.text())
.then(data => console.log(data));
// Output: Request HTTP Method: POSTThe server is built using Python's http.server module and implements handlers for common HTTP methods:
- GET: Returns "Request HTTP Method: GET"
- POST: Returns "Request HTTP Method: POST"
- PUT: Returns "Request HTTP Method: PUT"
- DELETE: Returns "Request HTTP Method: DELETE"
- PATCH: Returns "Request HTTP Method: PATCH"
- HEAD: Returns headers only (no body)
- OPTIONS: Returns allowed methods in the Allow header
All requests are logged with timestamps for debugging purposes.
Quickly verify that your HTTP client is sending the correct methods without needing a full backend.
Great for teaching and learning about HTTP methods and how they work in practice.
Use as a mock endpoint in your integration tests to verify HTTP method handling.
Confirm what HTTP method your application is actually sending when troubleshooting issues.
Deploy in containers for automated testing of API clients in your CI/CD pipeline.
The server configuration is straightforward:
- Port: Default is 80 (can be changed in
app.py) - Host: Listens on all interfaces (0.0.0.0)
- Logging: INFO level by default
The included Dockerfile uses Python 3.12.1-slim as the base image and exposes port 80. To deploy:
# Build
docker build -t echo-server .
# Run with custom port mapping
docker run -d -p 3000:80 --name my-echo-server echo-server
# Check logs
docker logs my-echo-server
# Stop
docker stop my-echo-serverContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source. Please check the repository for specific license information.
If you encounter any issues or have questions, please open an issue on GitHub.
[!Note]: This is a development/testing tool. It's not intended for production use without proper security considerations and enhancements.