A gRPC framework built upon Tonic using the Rust language.
This project aims to create ergonomic abstractions comparable to frameworks in other languages while attempting to maintain the performance benefits of Rust.
- Tonic Server
- Multi-Database Support (CockroachDB, Postgres, MySQL, Sqlite)
- JWT Support
- Async Caching Layer with a Simple API
- .env for Local Development
- Integrated Application State with a Simple API
- Lazy Static Config struct
- Built-in Healthcheck
- Listeners configured for TDD
- Custom Errors
- Secure Argon2i Password Hashing
- Unit and Integration Tests
- Test Coverage Reports
- Dockerfile for Running the Server in a Container
- TravisCI Integration
Argon2i
: Argon2i Password Hasningdotenv
: Configuration Loader (.env)envy
: Deserializes Environment Variables into a Config Structkcov
: Coverage Analysis
You can skip the first portion and jump ahead to the TBD
section of this setup by copying the skeleton code in the /examples
folder.
First, create a new project:
cargo new grpc_server --bin
Next, cd into the grpc_server
folder and add the following to Cargo.toml:
[package]
name = "grpc_server"
version = "0.1.0"
authors = ["YOUR NAME <yourname@yourdomain.com>"]
edition = "2018"
[dependencies]
grpc-framework = { path = "../", features = ["postgres"] }
dotenv = "0.14"
listenfd = "0.3"
log = "0.4"
pretty_env_logger = "0.4.0"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
With that setup in place, you can add in the server code in /src/main.rs
:
use grpc_framework::error::Result;
use grpc_framework::server::serve;
use grpc_framework::state::State;
#[tokio::main]
async fn main() -> Result<()> {
dotenv::dotenv().ok();
pretty_env_logger::init();
// we're storing String values in state, but it can be anything that
// fits in a hashmap
let state = State::<String>::new().await?;
serve(state).await?;
Ok(())
}
Create an .env file at the root of your project:
touch .env
Now add environment values for local development:
SERVER=[::1]:50051
IMPORTANT: Change .env values for your setup.
To startup the server:
RUST_LOG=info cargo run