Enables gRPC clients to work inside Spin components using wasi-hyperium and the spin-rust-sdk.
Spin is a fast, secure WebAssembly framework for serverless apps. This project extends Spin's capabilities by enabling components to make outbound gRPC requests, bridging the gap between Wasm sandboxing and modern microservice communication.
- 🧩 gRPC over HTTP/2 support inside Spin apps
- 🔐 Compatible with the Spin sandbox security model
- 🦀 Built with
wasi-hyperiumandtonic - 🌍 Works with most standard gRPC services
- 🧪 Great for calling internal microservices or public gRPC APIs from Spin
[dependencies]
anyhow = "1"
futures = "0.3.28"
prost = "0.13.5"
wasi-grpc = "0.1.0"
spin-sdk = "4.0.0"
tonic = { version = "0.13.1", features = ["codegen", "prost", "router"], default-features = false}In build.rs:
fn main() {
tonic_build::configure()
.type_attribute("routeguide.Point", "#[derive(Hash)]")
.build_transport(false)
.compile_protos(&["route_guide.proto"], &[""])
.unwrap();
}And in Cargo.toml:
[build-dependencies]
tonic-build = { version = "0.13.1", features = ["prost"] }let endpoint = WasiGrpcEndpoint::new(endpoint_uri);
let mut client = RouteGuideClient::new(endpoint);
let response = client.get_feature(Request::new(Point {
latitude: 409_146_138,
longitude: -746_188_906,
})).await?;This project assumes execution in a Spin-compliant runtime that allows outbound networking via Spin's capability-based model. Ensure your spin.toml includes the appropriate allowed_outbound_hosts granting outbound access to your gRPC service's endpoint.
This repo also contains the wasi-grpc-server crate, which provides a helper for writing gRPC services as wasi:http handlers. See the crate documentation for more information.