g2h: gRPC to HTTP Bridge Generator
Seamlessly expose your gRPC services as HTTP/JSON endpoints using Axum
g2h (gRPC-to-HTTP) automatically generates Axum HTTP handlers for your gRPC services, allowing them to be consumed by both gRPC clients and traditional web clients using HTTP/JSON.
Features
- 🔄 Automatic conversion between gRPC and HTTP/JSON
- 🛣️ Creates Axum routes that match gRPC service methods
- 🔌 Works with existing Tonic services with zero modification
- 🧠 Preserves metadata and headers between protocols
- 🚦 Proper error status conversion from gRPC to HTTP
Quick Start
# Cargo.toml
[]
= "0.13.0"
= "0.13.5"
= "0.7.0"
= { = "1.0", = ["derive"] }
[]
= "0.1.0"
= "0.13.0"
= "0.13.5"
// In your build.rs
use BridgeGenerator;
// In your main.rs - Create an Axum app with your gRPC service
let my_service = default;
let http_router = my_service_handler;
let app = new.nest;
Now your service is accessible through both gRPC and HTTP:
POST /api/package.ServiceName/MethodName
Content-Type: application/json
{
"field": "value"
}
Documentation
For complete usage examples and API documentation:
How It Works
g2h extends the standard gRPC code generation pipeline to create additional Axum router functions. These routers map HTTP POST requests to their corresponding gRPC methods, handling serialization/deserialization and status code conversion automatically.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Built by Human, Documented by LLM.