Add optional rustapi-grpc crate (tonic/prost)#118
Conversation
Introduce a new optional crate `rustapi-grpc` providing gRPC integration helpers built on Tonic/Prost. Exposes helpers (run_concurrently, run_rustapi_and_grpc, run_rustapi_and_grpc_with_shutdown), re-exports `tonic` and `prost`, and includes unit tests and documentation. Wire the crate into the workspace and the `rustapi-rs` facade as a feature-gated module (feature `grpc`), add the feature to the `full` meta-feature, and surface the option in the `cargo rustapi new` interactive template. Also update workspace Cargo.toml to declare tonic/prost, expand tokio features for the CLI crate, add docs/README entries, and update Cargo.lock accordingly.
There was a problem hiding this comment.
Pull request overview
Adds first-class (feature-gated) gRPC support to the RustAPI workspace by introducing a new optional rustapi-grpc crate built on tonic/prost, and wiring it into the rustapi-rs facade, docs, and project scaffolding.
Changes:
- Introduces new
rustapi-grpccrate with helpers to run HTTP + gRPC servers concurrently (with shared shutdown) and re-exports fortonic/prost. - Integrates
grpcas an optionalrustapi-rsfeature (included infull) and exposes it incargo rustapi newinteractive feature selection. - Updates workspace dependencies/docs (cookbook + root README) and lockfile for new gRPC-related deps.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/cookbook/src/crates/rustapi_grpc.md | New cookbook page documenting rustapi-grpc usage via rustapi-rs feature. |
| docs/cookbook/src/crates/README.md | Adds rustapi-grpc to the cookbook’s crate index. |
| docs/cookbook/src/SUMMARY.md | Adds rustapi-grpc to mdBook navigation. |
| crates/rustapi-rs/src/lib.rs | Feature-gated grpc module + prelude re-exports for the new helpers. |
| crates/rustapi-rs/Cargo.toml | Adds optional rustapi-grpc dep, grpc feature, and includes it in full. |
| crates/rustapi-grpc/src/lib.rs | New gRPC helper APIs + unit tests. |
| crates/rustapi-grpc/README.md | New crate README documenting helpers and example usage. |
| crates/rustapi-grpc/Cargo.toml | New crate manifest with tonic/prost deps. |
| crates/cargo-rustapi/src/commands/new.rs | Adds grpc to interactive feature selection list and defaults. |
| crates/cargo-rustapi/Cargo.toml | Expands Tokio features enabled for the CLI crate. |
| README.md | Updates feature highlights, roadmap checkboxes, and adds cookbook link for gRPC. |
| Cargo.toml | Adds rustapi-grpc workspace member and declares workspace tonic/prost deps. |
| Cargo.lock | Updates lockfile to include gRPC dependency graph. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```rust,ignore | ||
| use rustapi_rs::grpc::{run_rustapi_and_grpc, tonic}; | ||
| use rustapi_rs::prelude::*; | ||
|
|
||
| #[rustapi_rs::get("/health")] | ||
| async fn health() -> &'static str { "ok" } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
| let http_app = RustApi::new().route("/health", get(health)); | ||
|
|
||
| let grpc_addr = "127.0.0.1:50051".parse()?; | ||
| let grpc_server = tonic::transport::Server::builder() | ||
| .add_service(MyGreeterServer::new(MyGreeter::default())) | ||
| .serve(grpc_addr); | ||
|
|
||
| run_rustapi_and_grpc(http_app, "127.0.0.1:8080", grpc_server).await?; | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
This README is for the rustapi-grpc crate, but the examples import from rustapi_rs::grpc. That makes it hard to copy/paste when depending on rustapi-grpc directly. Consider updating the examples to use rustapi_grpc + rustapi_core, or add a short section that clearly distinguishes “via rustapi-rs feature grpc” vs “direct rustapi-grpc usage”.
| rustapi-core = { workspace = true } | ||
| tokio = { workspace = true, features = ["macros"] } | ||
| tonic = { workspace = true, features = ["transport"] } | ||
| prost = { workspace = true } |
There was a problem hiding this comment.
rustapi-grpc uses tokio::spawn and tokio::sync::watch, but the dependency only enables the macros feature. Other crates in this workspace explicitly list the Tokio features they rely on; consider adding the needed Tokio features here as well (at least rt and sync, and optionally time only for tests) so the crate doesn’t implicitly depend on Tokio default features or a workspace-wide configuration.
| //! use rustapi_rs::grpc::{run_rustapi_and_grpc, tonic}; | ||
| //! use rustapi_rs::prelude::*; | ||
| //! | ||
| //! #[rustapi_rs::get("/health")] |
There was a problem hiding this comment.
The rustapi-grpc crate-level docs show usage via rustapi_rs::grpc, but this crate depends on rustapi-core (not rustapi-rs). For docs.rs readers, it’s confusing that the primary example requires a different crate + feature flag. Consider switching the example imports to rustapi_grpc::{...} and rustapi_core::{...} (or explicitly document that the recommended entry point is rustapi-rs with features = ["grpc"]).
| //! use rustapi_rs::grpc::{run_rustapi_and_grpc, tonic}; | |
| //! use rustapi_rs::prelude::*; | |
| //! | |
| //! #[rustapi_rs::get("/health")] | |
| //! use rustapi_grpc::{run_rustapi_and_grpc, tonic}; | |
| //! use rustapi_core::{get, RustApi}; | |
| //! | |
| //! #[rustapi_core::get("/health")] |
|
@copilot open a new pull request to apply changes based on the comments in this thread |
…so-many Add optional rustapi-grpc crate (tonic/prost) ea86f97
Introduce a new optional crate
rustapi-grpcproviding gRPC integration helpers built on Tonic/Prost. Exposes helpers (run_concurrently, run_rustapi_and_grpc, run_rustapi_and_grpc_with_shutdown), re-exportstonicandprost, and includes unit tests and documentation. Wire the crate into the workspace and therustapi-rsfacade as a feature-gated module (featuregrpc), add the feature to thefullmeta-feature, and surface the option in thecargo rustapi newinteractive template. Also update workspace Cargo.toml to declare tonic/prost, expand tokio features for the CLI crate, add docs/README entries, and update Cargo.lock accordingly.Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of Change
Checklist
Testing
Please describe the tests that you ran to verify your changes:
Additional Notes
This pull request introduces first-class gRPC support to RustAPI via a new optional crate,
rustapi-grpc, powered by Tonic. It adds new helpers for running HTTP and gRPC servers side-by-side, updates documentation and CLI tooling, and integrates the feature into the workspace and project templates.New gRPC Integration:
rustapi-grpc, providing helpers to run RustAPI HTTP and Tonic gRPC servers concurrently, with shared shutdown support and re-exports oftonicandprostfor user convenience. [1] [2] [3] [4]rustapi-grpcand added it as an optional dependency and feature inrustapi-rsfor easy opt-in. [1] [2] [3] [4]fullfeature set and documentation to include gRPC, and re-exported the new helpers in the prelude for ergonomic usage. [1] [2] [3] [4]Documentation and Cookbook Updates:
README.mdand cookbook to document gRPC support, including a new integration guide and feature highlights. [1] [2] [3] [4] [5]CLI and Project Template Improvements:
cargo rustapi new) to supportgrpcas a selectable feature in new projects, and ensured template defaults are updated accordingly.Dependency Management:
tonicandprostas dependencies in the workspace for gRPC support, and expandedtokiofeatures incargo-rustapito support gRPC server needs. [1] [2]