/todo-rust-api

My first Rust API

Primary LanguageRust

Todo Rust API

Rust lang logo

My first Rust API.

It's a simple todo list API with CRUD operations.

This is a Proof of Concept to learn Rust with a practical example.

graph LR

A[HTTP Client] -->|Method & Path & JSON|B[Rust Rest API]
B -->|Queries|C[PostgreSQL database]
C -->|Rows|B
B -->|Status code & JSON|A

Loading

Table of contents

Installation

Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Sources

Clone the repository and run the following command:

cargo run

Database

This API works with a PostgreSQL database.

First start a Postgres container:

docker run --name postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 postgres

Then connect to the database and run the SQL script in static/sql/ folder.

docker exec -it postgres psql -U postgres

Usage

CURL collection

See Shell script examples in static/rest/ folder.

Available operations

Method Endpoint Description
GET /todos Get all todos
GET /todos/:id Get a todo by id
POST /todos Create a todo
PUT /todos/:id Update a todo
DELETE /todos/:id Delete a todo

Schema

{
  "id": 1,
  "title": "Do something",
  "completed": false
}