This repository provides a basic boilerplate for building a Rust backend with Axum.
- Axum: Web framework for building HTTP services.
- SeaORM: Async & dynamic ORM for interacting with databases.
- Validator: For request data validation.
- Tower: Middleware framework for composing asynchronous service chains.
- Anyhow: Simplified error handling.
- PostgreSQL
- Sample Server: A basic server setup demonstrating the integration of SeaORM with a RESTful API.
- JWT Authentication Middleware: Basic JWT authentication middleware to secure specific routes.
- Cargo Generate Support: Easy project scaffolding with interactive configuration.
entity/
: Contains the entity definitions automatically generated by SeaORM.migration/
: Contains migration scripts for database schema evolution.server/
: Contains the server implementation, including routes and handlers.
- Rust
- Cargo
- Docker
- Cargo Generate
- Install cargo-generate if you haven't already:
cargo install cargo-generate
- Generate your project:
cargo generate --git https://github.com/akaike/axum-boilerplate-with-seaorm
This will:
- Create a new project with your chosen name
- Set up database configuration in
.env.example
- Configure JWT authentication (optional)
- Create your .env file from the template:
cp .env.example .env
- Update the
.env
file if necessary
docker compose up -d
cd migration
cargo run
cargo run
By default, the server runs on port 3000. To change this, adjust the configuration in /server/src/server.rs
Refer to the SeaORM Documentation for additional details on customizing entities and other advanced features.
GET /api/v1/todos/:id
- Get a todo by IDPOST /api/v1/todos
- Create a new todoPUT /api/v1/todos/:id
- Update a todoDELETE /api/v1/todos/:id
- Delete a todo
POST /api/v1/todos
Content-Type: application/json
{
"title": "My new todo"
}
PUT /api/v1/todos/:id
Content-Type: application/json
{
"title": "Updated todo",
"completed": true
}
DELETE /api/v1/todos/:id
Contributions are welcome! Please feel free to submit a Pull Request.