Skip to content

MikAoJk/rust-crud-rest-api

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

Docker compose

Make sure you have docker compose installed using this command:

docker compose --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

Note This will not work, you need a database to run the application locally se Run the applicaiton with dockercompose

cargo run

Running the application locally

Create docker image of the app

Creating a docker image should be as simple as

docker build -t rustapp .
🐘 Run the Postgres container and app
docker compose up 
🐘 Only run the Postgres container
docker compose up db
🧪 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

About

Simple CRUD Rest API in Rust

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •