Welcome to the Rust Web API Example repository! Dive into the source code of a simple yet powerful CRUD application crafted in Rust, seamlessly integrated with PostgreSQL for robust data management.
-
Start the PostgreSQL server in a Docker container:
docker-compose up -d db
-
Install the SQLX-CLI if not already installed and apply the "up" migration script to the PostgreSQL database:
# Install sqlx-cli cargo install sqlx-cli # Run migrations sqlx migrate run
-
Install the necessary crates and launch the web server:
cargo r -r
This project optimizes the final Docker image size by utilizing Ubuntu Chiselled as the base image. Therefore, it's essential to build this base Docker image initially before running the application.
Note that building the base image is a one-time operation.
Building the base image:
docker buildx build -f Dockerfile.base --platform linux/arm64 --tag chiselled-ubuntu:latest . --load
Running the application:
docker compose up -d
To test the create endpoint, use the following curl
command:
curl -sS -H 'Content-Type: application/json' -X POST -d '{"book":"The Lord of the Rings", "quote":"Sometimes to find the light, We must first touch the darkness."}' http://localhost:8080/quotes | jq
To test the read endpoint, use the following curl
command:
curl http://localhost:8080/quotes | jq