A Rust example of a todo application with axum and sqlx.
- Rust
- Postgres
- sqlx
- sqlx-cli
- Docker (optional)
- axum
- tokio
- sqlx
- sqlx-cli
- serde
- serde_json
- dotenv
- chrono
- utoipa
- askama (for frontend with tailwindcss)
$ make db:up # make db:down to stop and db:destroy to remove
$ sqlx database create # create database
$ sqlx migrate run # run migrations
$ cargo run
If you want to watch for file changes, you can use cargo watch
:
$ make watch:install # Install cargo-watch
$ make watch
$ cargo build --release
$ ./target/release/rust-todo-api
Access the Swagger UI at /swagger-ui
and the OpenAPI spec
at /api-docs/openapi.json
.
You can also use RapiDoc at /rapidoc
.
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 }
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.