| Crates.io | foxy-io |
| lib.rs | foxy-io |
| version | 0.3.12 |
| created_at | 2025-04-26 17:21:34.554794+00 |
| updated_at | 2025-07-31 05:52:46.73588+00 |
| description | A configuration-driven and hyper-extensible HTTP proxy library |
| homepage | |
| repository | https://github.com/johan-steffens/foxy |
| max_upload_size | |
| id | 1650445 |
| size | 1,192,282 |
A minimal, configuration-driven, hyper-extensible Rust HTTP proxy library.
Foxy is ideal for:
Add Foxy to your Cargo.toml:
[dependencies]
foxy-io = "..."
Build an instance and start the server:
use foxy::Foxy;
// Create a new Foxy instance with layered configuration
let foxy = Foxy::loader()
.with_env_vars() // Environment variables (highest priority)
.with_config_file("config.toml") // File-based config (medium priority)
.with_config_file("defaults.toml") // Defaults (lowest priority)
.build().await?;
// Start the proxy server and wait for it to complete
foxy.start().await?;
git clone https://github.com/johan-steffens/foxy.git
cd foxy
export RUST_LOG=debug
export FOXY_CONFIG_FILE=$(pwd)/config/example.json
cargo run --bin foxy
Foxy uses platform-specific TLS backends to optimize for different build environments and avoid dependency issues.
git clone https://github.com/johan-steffens/foxy.git
cd foxy
cargo build --release
rustls-tls (pure Rust) to avoid OpenSSL build issues completelynative-tls with vendored OpenSSL for Docker buildsPrerequisites: Docker 20.10+ installed
Pull the multi-arch image:
docker pull johansteffens/foxy:latest
Run the proxy, exposing port 8080:
docker run --rm -p 8080:8080 johansteffens/foxy:latest
config.json file on your host0.0.0.0docker run --rm -p 8080:8080 \
-v "$(pwd)/config.json:/app/config.json:ro" \
-e FOXY_CONFIG_FILE=/app/config.json \
johansteffens/foxy:latest
Create a docker-compose.yml file:
version: "3.9"
services:
foxy:
image: johansteffens/foxy:latest
container_name: foxy
ports:
- "8080:8080"
environment:
FOXY_CONFIG_FILE: /config/config.json
volumes:
- ./config.json:/config/config.json:ro
Start the service:
docker compose up -d
Tip: When you update
config.json, restart withdocker compose restart foxyto apply changes.
Foxy uses a predicate-based routing system to determine how requests are handled:
Foxy's configuration can be provided through multiple sources:
// Build a layered configuration
let foxy = Foxy::loader()
.with_env_vars() // First priority
.with_config_file("config.json") // Second priority
.build().await?;
Example configuration:
{
"routes": [
{
"id": "api-route",
"target": "https://api.example.com",
"filters": [
{
"type": "path_rewrite",
"config": {
"pattern": "^/api/(.*)$",
"replacement": "/v2/$1"
}
}
],
"predicates": [
{
"type_": "path",
"config": {
"pattern": "/api/*"
}
}
]
}
]
}
For detailed configuration options, see the Configuration Guide.
Add JWT validation with the OIDC security provider:
{
"proxy": {
"security_chain": [
{
"type": "oidc",
"config": {
"issuer-uri": "https://id.example.com",
"jwks-uri": "https://id.example.com/.well-known/jwks.json",
"aud": "my-api",
"bypass": [
{ "methods": ["GET"], "path": "/health" }
]
}
}
]
}
}
This configuration validates all requests against the identity provider, while allowing public access to /health.
Foxy supports structured JSON logging for better observability in production environments:
{
"proxy": {
"logging": {
"structured": true,
"format": "json",
"include_trace_id": true,
"static_fields": {
"environment": "production",
"service": "api-gateway"
}
}
}
}
Key benefits:
For detailed configuration options, see the Configuration Guide.
Enable distributed tracing with OpenTelemetry:
# In your Cargo.toml
[dependencies]
foxy-io = { version = "...", features = ["opentelemetry"] }
Configure the OpenTelemetry collector in your configuration:
{
"proxy": {
"opentelemetry": {
"endpoint": "http://otel-collector:4317",
"service_name": "my-proxy-service",
"include_headers": true,
"resource_attributes": {
"host.name": "proxy-pod-abc123"
},
"collector_headers": {
"X-API-Key": "d41000b6-6191-47c5-99f1-7b88b1b97409"
}
}
}
}
Enable the Swagger UI feature:
# In your Cargo.toml
[dependencies]
foxy-io = { version = "...", features = ["swagger-ui"] }
Configure the OpenAPI schemas to be served on the Swagger UI in your configuration:
{
"proxy": {
"swagger_ui": {
"enabled": true,
"path": "/swagger-ui",
"sources": [
{
"name": "Petstore",
"url": "https://petstore.swagger.io/v2/swagger.json"
}
]
}
}
}
The vault-config feature enables secret interpolation from the filesystem into configuration values. This allows you to store sensitive information like passwords, API keys, and tokens in separate files and reference them in your configuration.
Add the vault-config feature to your Cargo.toml:
[dependencies]
foxy-io = { version = "0.3.6", features = ["vault-config"] }
Or enable it when building:
cargo build --features vault-config
/vault/secret/)${secret.name} syntaxVaultConfigProviderVault directory structure:
/vault/secret/
├── redis_password
Secret files content:
# /vault/secret/redis_password
super_secret_redis_password
Configuration file (config.json):
{
"server": {
"listen": "0.0.0.0:8080",
"redis_url": "redis://localhost:6379",
"redis_password": "${secret.redis_password}"
}
}
See examples/vault_example.rs for a complete working example:
cargo run --example vault_example --features vault-config
This example demonstrates:
Creating a temporary vault directory
Setting up secret files
Configuring the vault provider
Accessing interpolated configuration values
Foxy is designed to be highly extensible. You can inject your own custom logic into the proxy pipeline by implementing a few simple traits. This allows you to add custom routing rules, request/response modifications, and authentication mechanisms without forking the project.
The primary extension points are:
Filter: Modify requests and responses.Predicate: Implement custom routing logic.SecurityProvider: Add custom authentication and authorization.All extension points follow a similar pattern:
For a detailed guide on adding extension points, see the Extension Guide.
This project is licensed under the Mozilla Public License Version 2.0.
We welcome and appreciate contributions to Foxy! Please see our Contribution Guide for details on how to get involved, including our development workflow, code style, and testing procedures.
A big thank you to all the individuals who have contributed to Foxy!