Api Books

Example of Backend api rest in Rust 🦀

Technologies

  • Graphul
  • Postgresql
  • Diesel.rs

Setup

  1. Install Diesel.rs cli
cargo install diesel_cli
  1. Clone repository
git clone https://github.com/atticus64/books-api-rs
  1. 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
  1. Run migrations with diesel
diesel migration run
  1. Run server
cargo run

Endpoints

  • 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}