Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.54 KB

README.md

File metadata and controls

49 lines (38 loc) · 1.54 KB

Rust Web API Example

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.

Running the Project Locally

  1. Start the PostgreSQL server in a Docker container:

     docker-compose up -d db
  2. 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
  3. Install the necessary crates and launch the web server:

    cargo r -r

Running the Project in Docker

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

Testing

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