Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aarambhdevhub/rust-backend-axum
Master Rust backend development with Axum in this comprehensive tutorial. Learn user authentication, PostgreSQL integration, email verification, and secure APIs. Build scalable, production-ready apps using Rust. Source code and Postman collection available for easy testing.
https://github.com/aarambhdevhub/rust-backend-axum
authentication authentication-backend axum axum-authentication axum-extractor axum-framework axum-middleware axum-router axum-rs axum-server letter mail rust rust-language server sqlx sqlx-cli sqlx-postgres uuid validation
Last synced: 3 months ago
JSON representation
Master Rust backend development with Axum in this comprehensive tutorial. Learn user authentication, PostgreSQL integration, email verification, and secure APIs. Build scalable, production-ready apps using Rust. Source code and Postman collection available for easy testing.
- Host: GitHub
- URL: https://github.com/aarambhdevhub/rust-backend-axum
- Owner: AarambhDevHub
- License: mit
- Created: 2024-09-05T09:59:21.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-09-08T02:59:31.000Z (5 months ago)
- Last Synced: 2024-10-12T13:21:59.932Z (3 months ago)
- Topics: authentication, authentication-backend, axum, axum-authentication, axum-extractor, axum-framework, axum-middleware, axum-router, axum-rs, axum-server, letter, mail, rust, rust-language, server, sqlx, sqlx-cli, sqlx-postgres, uuid, validation
- Language: Rust
- Homepage: https://youtu.be/M0wi7V1rP4Y
- Size: 54.7 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust Backend with Axum, PostgreSQL, & Email Verification
[![Watch the video](https://img.youtube.com/vi/M0wi7V1rP4Y/maxresdefault.jpg)](https://youtu.be/M0wi7V1rP4Y)
This repository contains the source code for a fully functional backend application built with Rust, using the [Axum](https://github.com/tokio-rs/axum) framework. It includes user authentication, email verification, and a connection to a PostgreSQL database.
## ๐ ๏ธ Features
- **User Authentication**: Register, login, password reset functionality.
- **Email Verification**: Users receive an email to verify their accounts.
- **PostgreSQL Integration**: Store and manage user data securely.
- **JWT Authentication**: Secure API endpoints with JSON Web Tokens (JWT).
- **Middleware**: Implement custom middleware for authentication.
- **Testing with Postman**: A full Postman collection is provided to test all API endpoints.## ๐ Getting Started
### Prerequisites
To run this project, you will need:
- [Rust](https://www.rust-lang.org/) installed on your machine.
- [PostgreSQL](https://www.postgresql.org/) installed and running locally or remotely.
- [SQLx-CLI](https://crates.io/crates/sqlx-cli) for database migrations.
- [Postman](https://www.postman.com/) for testing API endpoints.### Installation
1. **Clone the repository:**
```bash
git clone https://github.com/AarambhDevHub/rust-backend-axum.git
cd rust-backend-axum
```2. **Install dependencies:**
```bash
cargo install --path .
```3. **Set up PostgreSQL:**
Create a new database in PostgreSQL and update the `.env` file with your database URL.
Example:
```
DATABASE_URL=postgres://user:password@localhost/dbname
```4. **Run migrations:**
```bash
sqlx migrate run
```5. **Start the server:**
```bash
cargo run
```The server will be running on `http://127.0.0.1:8000`.
## ๐ฌ Email Verification Setup
To enable email verification, you will need to configure an email service provider. Update the following environment variables in your `.env` file:
```env
SMTP_SERVER=smtp.your-email-provider.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your-email-password
```The application will send verification emails to users after registration.
## ๐งช API Testing with Postman
You can test all the API endpoints using the provided Postman collection. [Download the Postman collection here](https://github.com/AarambhDevHub/rust-backend-axum/blob/main/postman_collection.json) and import it into Postman.
API Endpoints:
POST `/api/auth/register`: Register a new user
POST `/api/auth/login`: Login with an existing user
GET `/api/auth/forgot-password`: Request password reset
POST `/api/auth/reset-password`: Reset user password
GET `/api/auth/verify`: Verify email with token
GET `/api/users/me`: Get current user profile (JWT required)
## โ๏ธ Configuration
The application requires a .env file for configuration. Below are the required environment variables:
```
# -----------------------------------------------------------------------------
# Database (PostgreSQL)
# -----------------------------------------------------------------------------
DATABASE_URL=postgresql://postgres:password@localhost:5432/axum_auth# -----------------------------------------------------------------------------
# JSON Web Token Credentials
# -----------------------------------------------------------------------------
JWT_SECRET_KEY=my_ultra_secure_jwt_secret_key
JWT_MAXAGE=60# -----------------------------------------------------------------------------
# SMTP Server Settings
# -----------------------------------------------------------------------------
SMTP_SERVER=smtp.your-email-provider.com
SMTP_PORT=587 # Common ports: 587 (TLS), 465 (SSL), 25 (non-secure)
[email protected]
SMTP_PASSWORD=your_email_password
[email protected]
```## ๐ฏ Future Enhancements
Add role-based access control (RBAC) for different user roles (admin, user).
Improve security with additional layers like rate limiting and input validation.
Expand API to include more features like user profiles, etc.## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.## โจ Acknowledgements
[Axum](https://github.com/tokio-rs/axum) for building powerful, fast APIs in Rust.
[PostgreSQL](https://www.postgresql.org/) for reliable database management.
[SQLx](https://github.com/launchbadge/sqlx) for async SQL in Rust.
## Donations
If you find this project useful and would like to support its continued development, you can make a donation via [Buy Me a Coffee](https://buymeacoffee.com/aarambhdevhub).
Thank you for your support!