Add streaming-tour and middleware examples#46
Conversation
ffe56f7 to
69bea69
Compare
|
[claude code] Updated per review feedback: switched proto packages from |
69bea69 to
1dff769
Compare
|
[claude code] Removed the IMPLICIT field-presence override, so the new examples now use edition 2023's actual defaults (EXPLICIT presence). All scalar/string fields are now |
1dff769 to
7095451
Compare
|
[claude code] Refactored the auth middleware from a hand-rolled |
484cf3a to
b2b499e
Compare
Two small example crates that close the most-asked-about gaps for new adopters. streaming-tour: a NumberService demonstrating all four ConnectRPC RPC types (unary, server stream, client stream, bidi stream) in one place. The methods are deliberately trivial - the example exists to show the wire-protocol shapes (handler signatures, client invocation patterns). middleware: server-side tower middleware composition around the connect router. A custom AuthLayer validates a Bearer token, stamps caller identity into request extensions, and short-circuits unauthorized requests with 401 in the Connect-protocol JSON error shape. TraceLayer and TimeoutLayer round out the stack via ServiceBuilder mounted on axum::Router. The handler reads the identity from Context::extensions() and writes a x-served-by response trailer via Context::set_trailer(). The client demonstrates ClientConfig::default_header for the auth header and CallOptions::with_timeout for per-call deadlines. Both examples ship server + client binaries plus integration tests that spin up the server in-process and exercise every code path.
b2b499e to
a2c412a
Compare
|
[claude code] CI was failing because Ubuntu's apt-installed protoc (v21.x) doesn't recognize
Local verification: |
| // After each request, emits the running total — letting the client | ||
| // observe the cumulative sum mid-stream rather than waiting for the | ||
| // end. | ||
| rpc RunningSum(stream RunningSumRequest) returns (stream RunningSumResponse); |
The generated `_with_options` doc comment used the shortcut intra-doc link form `[connectrpc::client::ClientConfig]`, which fails to resolve when the proto package contains `connectrpc` as a path component (e.g. `anthropic.connectrpc.tour.v1`). The package's nested module shadows the external crate name during rustdoc path resolution, producing 'no item named client in module connectrpc'. Switch to the reference-style form `[ClientConfig](::connectrpc::...)` with a leading `::` for absolute path resolution, matching the pattern already used for UnaryResponse on lines 685 and 694.
|
[claude code] CI green now (12/12 checks). The Documentation job was failing on a separate issue beyond the protoc version: a broken intra-doc link in generated client code. The codegen template at Existing examples don't hit this because they ship checked-in code with Fixed in the codegen by switching to the reference-style |
Closes #45
Adds two small focused example crates that close the most-asked-about gaps for new adopters: protocol-mechanics demonstration of all four RPC types, and server-side tower middleware composition.
examples/streaming-tour
A trivial `NumberService` exercising every ConnectRPC RPC type:
The methods are deliberately tiny - the example exists to show handler signatures and client invocation patterns side-by-side. Ships server + client binaries plus an integration test that spins up the server in-process and verifies every RPC.
examples/middleware
Server-side tower middleware composition around the connect router:
Layers compose via `ServiceBuilder` mounted on `axum::Router::layer()`, so axum handles body conversion from `ConnectRpcBody` to `axum::body::Body`. The handler reads `UserId` from `Context::extensions()`, performs a per-secret permission check, and writes a `x-served-by` response trailer via `Context::set_trailer()`.
The client demonstrates `ClientConfig::default_header` for the auth header, `ClientConfig::default_timeout` for a default deadline, and `CallOptions::with_timeout` for a per-call override. Integration tests cover four paths: authorized success (verifying the trailer arrives), missing auth header, invalid token, and permission denied.
Verification
Branch order note
This branch is off main (pre-#44). When #44 lands, I'll rebase this branch onto main and add `rust-version.workspace = true` to the two new examples' `Cargo.toml` to match the rest of the workspace.