Skip to main content

Module grpc

Module grpc 

Source
Available on crate features grpc and http only.
Expand description

gRPC helpers for serving tonic services. gRPC helpers for serving tonic services from Spin components.

This module provides a thin integration layer between the Spin HTTP subsystem and tonic-generated gRPC servers. Tonic’s generated server types (e.g. GreeterServer<T>) implement tower_service::Service over HTTP requests, so they can accept Spin’s incoming Request directly.

§Example

use spin_sdk::http::{IntoResponse, Request};
use spin_sdk::http_service;
#[http_service]
async fn handler(req: Request) -> impl IntoResponse {
    spin_sdk::grpc::serve(GreeterServer::new(MyGreeter), req).await
}

Functions§

serve
Serve a gRPC request by forwarding it to a tower service.