Expand description
ConnectRPC ClientTransport implementations backed by the Cloudflare
Workers fetch APIs.
Two transports are provided:
FetcherTransportwraps aworker::Fetcher(a[[services]]binding). Use it for inter-service calls within the same Cloudflare zone. The runtime short-circuits these requests, so there’s no DNS lookup, no TLS handshake, and no trip out to the public internet.FetchTransportwraps the globalworker::Fetchfor arbitraryhttp:///https://URLs.
§Sendness
ClientTransport requires Send + Sync + 'static on the type and a
Send + 'static future. Workers’ fetch is !Send (everything in
JS-land is !Send). We use worker::send::SendFuture /
worker::send::SendWrapper to satisfy the bound. workers-rs ships
these specifically because the Workers isolate is single-threaded, so
nothing is ever actually moved across threads.
§Protocol
Use connectrpc::Protocol::Connect (or GrpcWeb). Workers fetch
subrequests don’t expose raw HTTP/2, so gRPC’s trailer requirement
won’t survive. Connect over HTTP/1.1 and GrpcWeb (trailers in body)
both work.
§Example
ⓘ
use connectrpc::client::ClientConfig;
use connectrpc::Protocol;
use connectrpc_workers::FetcherTransport;
// Inside a #[event(fetch)] handler:
let echo = env.service("ECHO")?;
let transport = FetcherTransport::new(echo);
let config = ClientConfig::new("http://echo/".parse()?).protocol(Protocol::Connect);
let client = EchoServiceClient::new(transport, config);
let resp = client.echo(EchoRequest { message: "hi".into() }).await?;Structs§
- Fetch
Transport ClientTransportbacked by the global Workersfetch(arbitrary URL).- Fetcher
Transport ClientTransportbacked by a Workers service binding.