This is a showcase of a microservice written in Rust. The microservice exposes:
- An API for wihslists management;
- A swagger page to help testing and reasoning about the API;
- An OpenAPI JSON specification that can be used by a frontend or another service to auto-generate the types of data used by this microservice;
- Install rustup for rust version management;
- (Optional) Install cargo-watch for live reloading of the server: run
cargo install cargo-watch
to install it; - Create an
.env
file from theenv.template
. You need to set the PostgreSQL database URL there; - Run
cargo watch -x run
to start the server, and automatically apply your changes during development; - This project uses sqlx for database connection and compile-time validation of SQL queries. Therefore, you need to have the database available during compilation;
This project uses PostgreSQL as a database. We suggest running it in a docker container;
-
Make sure that you have docker installed, and that you are inside this project root folder;
-
Run
docker build database -t wishlist-db
to build an image for local development with testing data;
💡 To build a Postgres docker image with the tables, but without testing data for the production environment, you can run the following:
docker build database -t wishlist-db --build-arg ENV=production
-
Run
docker run -e POSTGRES_PASSWORD=<YOUR_PW> -p 5432:5432 wishlist-db
to run the Postgres container with port forwarding; -
Since Postgres is running on docker, changes in the database do not persist automatically. Nevertheless, you can follow these steps to persist your data:
4.1. Create a docker volume:
docker volume create postgres_data
;4.2. When running Postgres, pass the created volume as an argument:
docker run -e POSTGRES_PASSWORD=<YOUR_PW> -p 5432:5432 v postgres_data:/var/lib/postgresql/data wishlist-db
;