Skip to content

Add optional rustapi-grpc crate (tonic/prost)#118

Merged
Tuntii merged 1 commit intomainfrom
grpc-and-so-many
Feb 11, 2026
Merged

Add optional rustapi-grpc crate (tonic/prost)#118
Tuntii merged 1 commit intomainfrom
grpc-and-so-many

Conversation

@Tuntii
Copy link
Owner

@Tuntii Tuntii commented Feb 11, 2026

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.

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of Change

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Testing

Please describe the tests that you ran to verify your changes:

  • Unit tests
  • Integration tests
  • Manual testing
  • Other (please describe):

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:

  • Added a new crate, rustapi-grpc, providing helpers to run RustAPI HTTP and Tonic gRPC servers concurrently, with shared shutdown support and re-exports of tonic and prost for user convenience. [1] [2] [3] [4]
  • Updated workspace configuration to include rustapi-grpc and added it as an optional dependency and feature in rustapi-rs for easy opt-in. [1] [2] [3] [4]
  • Enhanced the full feature 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:

  • Updated the main README.md and cookbook to document gRPC support, including a new integration guide and feature highlights. [1] [2] [3] [4] [5]

CLI and Project Template Improvements:

  • Updated the interactive CLI (cargo rustapi new) to support grpc as a selectable feature in new projects, and ensured template defaults are updated accordingly.

Dependency Management:

  • Added tonic and prost as dependencies in the workspace for gRPC support, and expanded tokio features in cargo-rustapi to support gRPC server needs. [1] [2]

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.
Copilot AI review requested due to automatic review settings February 11, 2026 12:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-grpc crate with helpers to run HTTP + gRPC servers concurrently (with shared shutdown) and re-exports for tonic/prost.
  • Integrates grpc as an optional rustapi-rs feature (included in full) and exposes it in cargo rustapi new interactive 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.

Comment on lines +14 to +32
```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(())
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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”.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +19
rustapi-core = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
tonic = { workspace = true, features = ["transport"] }
prost = { workspace = true }
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +14
//! use rustapi_rs::grpc::{run_rustapi_and_grpc, tonic};
//! use rustapi_rs::prelude::*;
//!
//! #[rustapi_rs::get("/health")]
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]).

Suggested change
//! 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 uses AI. Check for mistakes.
@Tuntii
Copy link
Owner Author

Tuntii commented Feb 11, 2026

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 11, 2026

@Tuntii I've opened a new pull request, #119, to work on those changes. Once the pull request is ready, I'll request review from you.

@Tuntii Tuntii merged commit ea86f97 into main Feb 11, 2026
13 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 11, 2026
…so-many

Add optional rustapi-grpc crate (tonic/prost) ea86f97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants