Example of Backend api rest in Rust 🦀
- Graphul
- Postgresql
- Diesel.rs
- Install Diesel.rs cli
cargo install diesel_cli
- Clone repository
git clone https://github.com/atticus64/books-api-rs
- Start postgresql database (example with docker)
version: "3.3"
services:
db1:
container_name: rusty_postgre
image: postgres:13.4-alpine
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: books
- Execute docker-compose
docker compose up
- Run migrations with diesel
diesel migration run
- Run server
cargo run
- List books
curl localhost:8000/books
- Create book
curl localhost:8000/create -H 'Content-type: application/json' \
- Book in body Post Create and Update
struct BookData {
pub title: String,
pub description: String,
pub author: String,
pub published: bool,
}
- Update Book
curl -X PUT localhost:8000/books/{id}
- Delete Book
curl -X DELETE localhost:8000/books/{id}