Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rustapi-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"

[dependencies]
rustapi-core = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
tokio = { workspace = true, features = ["rt", "sync", "macros"] }
tonic = { workspace = true, features = ["transport"] }
prost = { workspace = true }

Expand Down
45 changes: 43 additions & 2 deletions crates/rustapi-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,55 @@
- `run_rustapi_and_grpc_with_shutdown(app, http_addr, signal, grpc_with_shutdown)`: shared shutdown signal for both servers.
- Re-exports: `tonic`, `prost`.

## Example
## Usage

### Via `rustapi-rs` (recommended)

Add to your `Cargo.toml`:

```toml
[dependencies]
rustapi-rs = { version = "0.1", features = ["grpc"] }
```

Then import via the `grpc` module:

```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" }
```

### Direct `rustapi-grpc` usage

Add to your `Cargo.toml`:

```toml
[dependencies]
rustapi-grpc = "0.1"
rustapi-core = "0.1"
```

Then import directly:

```rust,ignore
use rustapi_grpc::{run_rustapi_and_grpc, tonic};
use rustapi_core::{get, RustApi};

#[rustapi_core::get("/health")]
async fn health() -> &'static str { "ok" }
```

## Example

```rust,ignore
use rustapi_grpc::{run_rustapi_and_grpc, tonic};
use rustapi_core::{get, RustApi};

#[rustapi_core::get("/health")]
async fn health() -> &'static str { "ok" }

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Expand All @@ -35,7 +76,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
## Shared shutdown (Ctrl+C)

```rust,ignore
use rustapi_rs::grpc::{run_rustapi_and_grpc_with_shutdown, tonic};
use rustapi_grpc::{run_rustapi_and_grpc_with_shutdown, tonic};

let grpc_addr = "127.0.0.1:50051".parse()?;

Expand Down
25 changes: 19 additions & 6 deletions crates/rustapi-grpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
//!
//! ## Quick start
//!
//! When using `rustapi-grpc` directly:
//!
//! ```rust,ignore
//! use rustapi_rs::grpc::{run_rustapi_and_grpc, tonic};
//! use rustapi_rs::prelude::*;
//! use rustapi_grpc::{run_rustapi_and_grpc, tonic};
//! use rustapi_core::{get, RustApi};
//!
//! #[rustapi_rs::get("/health")]
//! #[rustapi_core::get("/health")]
//! async fn health() -> &'static str { "ok" }
//!
//! #[tokio::main]
Expand All @@ -27,6 +29,17 @@
//! Ok(())
//! }
//! ```
//!
//! Or use via `rustapi-rs` with the `grpc` feature:
//!
//! ```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" }
//! // ... rest of example
//! ```

#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
Expand Down Expand Up @@ -107,10 +120,10 @@ where
/// # Example
///
/// ```rust,ignore
/// use rustapi_rs::grpc::{run_rustapi_and_grpc_with_shutdown, tonic};
/// use rustapi_rs::prelude::*;
/// use rustapi_grpc::{run_rustapi_and_grpc_with_shutdown, tonic};
/// use rustapi_core::{get, RustApi};
///
/// #[rustapi_rs::get("/health")]
/// #[rustapi_core::get("/health")]
/// async fn health() -> &'static str { "ok" }
///
/// #[tokio::main]
Expand Down