Skip to content

This repository contains the source code of a sample CRUD application in Rust.

License

Notifications You must be signed in to change notification settings

akoken/rust-web-api

Repository files navigation

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

About

This repository contains the source code of a sample CRUD application in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Languages