Skip to content

adisusilayasa/rust-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust REST API

Tech Stack

  • 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

Prerequisites

  • Rust (latest stable)
  • PostgreSQL
  • Docker (optional)

Running Locally

  1. Clone the repository:
git clone https://github.com/adisusilayasa/rust-rest-api.git
cd rust-rest
  1. Copy the environment file:
cp .env.example .env
  1. Update the .env file with your database credentials

  2. Generate SQLx prepare file:

cargo sqlx prepare
  1. Run the migrations:
sqlx database create
sqlx migrate run
  1. Build and run the project:
cargo run

Running with Docker

### Using Docker directly

1. Generate SQLx prepare file first:
```bash
cargo sqlx prepare
  1. Build the Docker image:
docker build -t rust-rest-api .
  1. 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

API Endpoints

  • 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

Environment Variables

  • DATABASE_URL: PostgreSQL connection string
  • JWT_SECRET: Secret key for JWT tokens
  • PORT: Server port (default: 8080)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors