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
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Clone the repository and run the following command:
cargo run
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
See Shell script examples in static/rest/
folder.
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 |
{
"id": 1,
"title": "Do something",
"completed": false
}