Expand description
gRPC runtime support for Spikard
This module provides gRPC server infrastructure using Tonic, enabling Spikard to handle both HTTP/1.1 REST requests and HTTP/2 gRPC requests.
§Architecture
The gRPC support follows the same language-agnostic pattern as the HTTP handler:
- GrpcHandler trait: Language-agnostic interface for handling gRPC requests
- Service bridge: Converts between Tonic’s types and our internal representation
- Streaming support: Utilities for handling streaming RPCs
- Server integration: Multiplexes HTTP/1.1 and HTTP/2 traffic
§Example
ⓘ
use spikard_http::grpc::{GrpcHandler, GrpcRequestData, GrpcResponseData};
use std::sync::Arc;
// Implement GrpcHandler for your language binding
struct MyGrpcHandler;
impl GrpcHandler for MyGrpcHandler {
fn call(&self, request: GrpcRequestData) -> Pin<Box<dyn Future<Output = GrpcHandlerResult> + Send>> {
Box::pin(async move {
// Handle the gRPC request
Ok(GrpcResponseData {
payload: bytes::Bytes::from("response"),
metadata: tonic::metadata::MetadataMap::new(),
})
})
}
fn service_name(&self) -> &str {
"mypackage.MyService"
}
}
// Register with the server
let handler = Arc::new(MyGrpcHandler);
let config = GrpcConfig::default();Re-exports§
pub use framing::parse_grpc_client_stream;pub use handler::GrpcHandler;pub use handler::GrpcHandlerResult;pub use handler::GrpcRequestData;pub use handler::GrpcResponseData;pub use handler::RpcMode;pub use service::GenericGrpcService;pub use service::copy_metadata;pub use service::is_grpc_request;pub use service::parse_grpc_path;pub use streaming::MessageStream;pub use streaming::StreamingRequest;pub use streaming::StreamingResponse;
Modules§
- framing
- HTTP/2 gRPC frame parsing for client streaming support
- handler
- Core GrpcHandler trait for language-agnostic gRPC request handling
- service
- Tonic service bridge
- streaming
- Streaming support utilities for gRPC
Structs§
- Grpc
Config - Configuration for gRPC support
- Grpc
Registry