| Crates.io | exchange |
| lib.rs | exchange |
| version | 0.1.0 |
| created_at | 2025-11-17 12:28:40.600945+00 |
| updated_at | 2025-11-17 12:28:40.600945+00 |
| description | A minimal, configuration-driven HTTP reverse proxy built with hyper and tokio. |
| homepage | |
| repository | https://github.com/shadertheory/exchange |
| max_upload_size | |
| id | 1936713 |
| size | 72,323 |
A minimal, configuration-driven reverse proxy in Rust, built with hyper, reqwest, and tokio.
It reads a proxy.toml file at startup to configure routes and server settings, forwarding incoming requests to the appropriate upstream services.
proxy.toml file.wildcard = true to match all sub-paths of a given pattern.reqwest's connection pool for efficient upstream connections.Create a proxy.toml file in the same directory where you run the application.
proxy.toml# The port the proxy server will listen on
port = 8080
# --- Optional Settings ---
# Max request body size in bytes (default: 1048576, or 1MB)
max_body_bytes = 2097152 # 2MB
# Upstream request timeout (default: 5s)
# Uses serde's Duration format
gateway_timeout = { secs = 10, nanos = 0 }
# --- Routes ---
# An exact-match route
# Requests to "http://localhost:8080/api/users"
# will be proxied to "http://users-service:3000/api/users"
[[routes]]
pattern = "/api/users"
target = "http://users-service:3000"
# wildcard = false (this is the default)
# A wildcard route
# Requests to "http://localhost:8080/assets/main.css"
# will be proxied to "http://static-files:9000/assets/main.css"
[[routes]]
pattern = "/assets"
target = "http://static-files:9000"
wildcard = true
port (u16, Required): The port for the proxy to listen on.max_body_bytes (u64, Optional): The maximum allowed request body size in bytes.
1048576 (1MB)gateway_timeout (Duration, Optional): The time to wait for a response from the upstream service.
{ secs = 5, nanos = 0 } (5 seconds)connection_pool_size (usize, Optional): Max idle connections per upstream host.
[[routes]] (Array, Required): A list of route objects.
pattern (string): The incoming URI path to match.target (string): The base URI of the upstream service to forward to.wildcard (bool, Optional): If true, matches any path that starts with the pattern. If false (default), requires an exact path match.Exchange listens for incoming requests and matches them against its list of routes.
GET /assets/img.png).port.[[routes]] entry with pattern = "/assets" and wildcard = true.http://static-files:9000 (target) + /assets/img.png (original path).If no route matches, a 404 Not Found is returned. If the incoming request body exceeds max_body_bytes, a 413 Payload Too Large is returned.
Ensure you have Rust and Cargo installed.
Create your proxy.toml file in the project's root directory.
Run the server in release mode:
cargo run --release
The proxy will start on the port specified in your config file.
Proxy server running on http://0.0.0.0:8080
Press Ctrl+C to stop