todo-tonic-sqlx-refinery-barrel
todo-tonic-sqlx-refinery-barrel copied to clipboard
A simple Todo GRPC server using Tonic, SQLx, Refinery and Barrel
GRPC Server with Rust, tonic, sqlx, refinery and barrel
This repository is an example of how I setup a GRPC server in Rust. The components include:
- Tonic Tonic as the GRPC server framework
- SQLx as SQL toolkit. I chose to use this as it supports asynchronous operations, has a built-in mapper between Rust Struct and database tables as well as a built-in connection pooler.
- refinery is used to setup database migrations
- barrel allows me to create database migration scripts in Rust.
Services
This service exposes 4 RPC calls:
AddTodoto create a todo itemAllTodosto list all todo itemsIncompleteto list all incomplete todo itemsGetTodoto get a detail of a todo itemMarkCompleteto mark a todo item as completed
Running the Binaries
This repository has two binaries:
todo(which can be run fromcargo run --bin todo) is the main GRPC servermigrate(which can be run fromcargo run --bin migrate) is the binary to execute database migrations
If you're building this, please set your environment configuration from .env file (copied from .env.example). Then you can run cargo run --bin migrate to create the table. Finally, you can then run cargo run --bin todo to run GRPC server.
Testing from Client
I've been using evans as a GRPC client to test for the service. Use the following command to connect:
evans --host 127.0.0.1 --proto proto/todo.proto
To call any of the RPCs listed above, you can just use call command (e.g call AddTodo)
Screenshot
