Skip to content

MikAoJk/rust-crud-rest-api

Repository files navigation

rust-crud-rest-api

Prerequisites

Make sure you have the rust installed using this command:

Rust

rustc --version

Cargo

Make sure you have cargo installed using this command:

cargo --version

Docker

Make sure you have docker installed using this command:

docker --version

Curl

Make sure you have curl installed using this command:

curl --version

Build code

Build the code without running it

cargo build

Test code

Build the code and run all the tests

cargo test

Run code

Build the code and run all the tests

cargo run

Running the application locally

Create docker image of app

Creating a docker image should be as simple as

docker build -t rustapp .
🐘 Run the Postgres container
docker-compose up -d db
🏗️ Build the Rust app image
docker compose build
👟 Run the Rust Container
docker compose up rustapp
🧪 Test the applications endpoints

Request to get the all the users:

curl --location --request GET 'http://localhost:8080/users'

Example of a response: [ { "id": 1, "name": "aaa", "email": "aaa@mail" }, { "id": 2, "name": "bbb", "email": "bbb@mail" } ]

Request to create a new user

curl --location --request POST 'http://localhost:8080/users' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "aaa","email": "aaa@mail"}'

Request to get one specific user:

curl --location --request GET 'http://localhost:8080/users/2'

Example of a response: { "name": "new", "email": "new@mail" }

Request to update a user

curl --location --request PUT 'http://localhost:8080/users/2' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "new","email": "new@mail"}'

Request to delete a user

curl --location --request DELETE 'http://localhost:8080/users/3'

Contact

This project is maintained by MikAoJk