A configurable HTTP echo server with advanced features for testing and mocking HTTP endpoints.
- Request echoing with detailed request information
- Path-based configuration with regex support
- Request counting (global and per-path)
- Customizable responses (status codes, headers, body)
- Configurable response delays
- Error injection capabilities
- Thread-safe operations
- REST API for configuration management
- Proxy support for upstream servers
- Web UI for configuration and testing
Configure and manage endpoint behaviors with regex pattern matching, methods, and responses.
Test endpoints with custom methods, paths, and request bodies.
Monitor request counts per endpoint and manage counters.
Built-in documentation and configuration examples.
go get github.com/yourusername/echo-server- Run the server:
go run cmd/server/main.go- Access the web UI:
http://localhost:8080
- Make a test request:
curl http://localhost:8080/testCreate a config/server.json file:
{
"host": "localhost",
"port": 8080,
"readTimeout": "30s",
"writeTimeout": "30s",
"defaultResponse": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
}
}
}Create path configurations in config/paths/:
{
"name": "api",
"pattern": "^/api/.*",
"methods": ["GET", "POST"],
"response": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"status\":\"ok\"}",
"delay": "100ms"
},
"errorResponse": {
"statusCode": 500,
"body": "{\"error\":\"internal server error\"}"
},
"errorEvery": 5,
"counterEnabled": true
}Configure proxy settings for specific paths:
{
"name": "proxy-endpoint",
"pattern": "^/proxy/.*",
"methods": ["GET", "POST", "PUT", "DELETE"],
"proxy": {
"url": "http://upstream-api.example.com",
"timeout": "30s",
"stripPrefix": true,
"preserveHost": false,
"allowedHeaders": ["Authorization", "Content-Type"],
"forwardHeaders": ["X-Request-ID"]
}
}GET /config/paths- List all path configurationsPOST /config/paths- Add new path configurationPUT /config/paths/{pattern}- Update existing path configuration
GET /counter- Get all countersDELETE /counter/{path}- Reset counter for specific pathDELETE /counter- Reset all counters
Use Go templates in response bodies:
{
"body": "template:{\"path\":\"{{.Path}}\",\"method\":\"{{.Method}}\"}"
}Configure error responses with frequency:
{
"errorResponse": {
"statusCode": 500,
"body": "{\"error\":\"random error\"}"
},
"errorFrequency": 0.1
}Enable request counting per path:
{
"counterEnabled": true
}Usage:
echo-server [options]
Options:
-port int
Port to run the server on (default 8080)
-config string
Path to configuration directory (default "./config")
-upstream string
Upstream server URL to proxy requests to
-proxy-timeout duration
Timeout for proxy requests (default 30s)
-help
Show this help message
echo-server/
├── cmd/
│ └── server/
│ └── main.go
├── config/
│ ├── server.json
│ └── paths/
├── internal/
│ ├── config/
│ ├── counter/
│ ├── handler/
│ ├── matcher/
│ ├── middleware/
│ └── model/
├── pkg/
│ └── logger/
└── README.md
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.