Skip to main content

Crate rustapi_grpc

Crate rustapi_grpc 

Source
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§

pub use tonic;
pub use prost;

Functions§

run_concurrently
Run two independent servers/tasks concurrently.
run_rustapi_and_grpc
Run a RustApi HTTP 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.
ShutdownFuture
Shutdown future type used by gRPC server builders.