Skip to content

litsynp/rust-axum-todo-api

Repository files navigation

rust-axum-todo-api

A Rust example of a todo application with axum and sqlx.

Requirements

  • Rust
  • Postgres
  • sqlx
  • sqlx-cli
  • Docker (optional)

Dependencies

  • axum
  • tokio
  • sqlx
  • sqlx-cli
  • serde
  • serde_json
  • dotenv
  • chrono
  • utoipa
  • askama (for frontend with tailwindcss)

Run the Application

Docker

$ make db:up  # make db:down to stop and db:destroy to remove

Database Setup

$ sqlx database create # create database
$ sqlx migrate run # run migrations

Run (Development)

$ cargo run

If you want to watch for file changes, you can use cargo watch:

$ make watch:install  # Install cargo-watch
$ make watch

Run (Production)

$ cargo build --release
$ ./target/release/rust-todo-api

Swagger / OpenAPI

Access the Swagger UI at /swagger-ui and the OpenAPI spec at /api-docs/openapi.json.

You can also use RapiDoc at /rapidoc.

Troubleshooting

CLI

This project includes a CLI to add users to the database.

$ cargo run --bin add-user -- [email protected] --nickname=user --password=1234
Successfully registered user User { id: 1, email: "[email protected]", password: "1234", nickname: "user", created_at: 2024-04-19T17:14:54.358424Z, updated_at: 2024-04-19T17:14:54.358424Z, deleted_at: None }

Frontend

This project uses askama to render HTML templates.

If you need to access the frontend, you can run the following command:

$ npm install
$ npm run tailwind:build # or npm run tailwind:watch to watch for changes

Go to index page at / and login at /login.

You can add, edit and delete todos.

Releases

No releases published

Packages

No packages published