- Actix-web: Web framework
- SQLx: PostgreSQL async driver
- Tokio: Async runtime
- Serde: Serialization/Deserialization
- JWT: Authentication
- bcrypt: Password hashing
- Chrono: DateTime handling
- UUID: Unique identifiers
- env_logger: Logging
- Rust (latest stable)
- PostgreSQL
- Docker (optional)
- Clone the repository:
git clone https://github.com/adisusilayasa/rust-rest-api.git
cd rust-rest- Copy the environment file:
cp .env.example .env-
Update the
.envfile with your database credentials -
Generate SQLx prepare file:
cargo sqlx prepare- Run the migrations:
sqlx database create
sqlx migrate run- Build and run the project:
cargo run### Using Docker directly
1. Generate SQLx prepare file first:
```bash
cargo sqlx prepare
- Build the Docker image:
docker build -t rust-rest-api .- Run the container:
docker run -p 8080:8080 \
-e DATABASE_URL="postgresql://<username>:<password>@host.docker.internal:5432/rust_rest" \
-e JWT_SECRET="your_secret_key" \
-e PORT="8080" \
rust-rest-api- Health Check:
GET /health - Authentication:
POST /api/auth/login - User Registration:
POST /api/auth/register - User Profile:
GET /api/users/profile - Update Profile:
PUT /api/users/profile
DATABASE_URL: PostgreSQL connection stringJWT_SECRET: Secret key for JWT tokensPORT: Server port (default: 8080)