Expand description
§rustapi-grpc
gRPC integration helpers for RustAPI using tonic.
This crate keeps RustAPI’s facade approach: your app code stays simple while you can run a RustAPI HTTP server and a Tonic gRPC server side-by-side in the same process.
§Quick start
ⓘ
use rustapi_rs::grpc::{run_rustapi_and_grpc, tonic};
use rustapi_rs::prelude::*;
#[rustapi_rs::get("/health")]
async fn health() -> &'static str { "ok" }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let http_app = RustApi::new().route("/health", get(health));
let grpc_addr = "127.0.0.1:50051".parse()?;
let grpc_server = tonic::transport::Server::builder()
.add_service(MyGreeterServer::new(MyGreeter::default()))
.serve(grpc_addr);
run_rustapi_and_grpc(http_app, "127.0.0.1:8080", grpc_server).await?;
Ok(())
}Re-exports§
Functions§
- run_
concurrently - Run two independent servers/tasks concurrently.
- run_
rustapi_ and_ grpc - Run a
RustApiHTTP server and any gRPC future side-by-side. - run_
rustapi_ and_ grpc_ with_ shutdown - Run RustAPI HTTP and gRPC servers together with a shared shutdown signal.
Type Aliases§
- BoxError
- Boxed error used by this crate.
- Result
- Result type used by this crate.
- Shutdown
Future - Shutdown future type used by gRPC server builders.