A high-performance Rust-based web API service built with Actix-web, designed for deployment on Railway.
SPOQ Web APIs provides a robust backend service with GitHub OAuth authentication, database integration via PostgreSQL, and modern security features including JWT authentication and rate limiting.
- Built with Actix-web 4.x for high performance
- PostgreSQL database integration with SQLx
- GitHub OAuth authentication
- JWT-based session management
- Rate limiting with actix-governor
- Structured logging with tracing
- Multi-stage Docker builds for optimized deployment
- Railway-ready configuration
- Framework: Actix-web 4.12
- Database: PostgreSQL (via SQLx 0.8)
- Auth: GitHub OAuth + JWT (jsonwebtoken 9)
- Security: Argon2 password hashing, rate limiting
- HTTP Client: Reqwest 0.12 with rustls
- Runtime: Tokio 1.49
- Observability: Tracing + tracing-subscriber
- Rust 1.84 or later
- PostgreSQL 14 or later
- GitHub OAuth App (for authentication)
- Clone the repository:
git clone <repository-url>
cd spoq-web-apis- Set up environment variables:
cp .env.example .envEdit .env with your configuration:
# Database Configuration
DATABASE_URL=postgres://user:pass@localhost:5432/spoq
# GitHub OAuth Configuration
GITHUB_CLIENT_ID=your_client_id
GITHUB_CLIENT_SECRET=your_client_secret
GITHUB_REDIRECT_URI=http://localhost:8080/auth/github/callback
# JWT Configuration
JWT_SECRET=your_jwt_secret_min_32_chars
# Server Configuration
HOST=0.0.0.0
PORT=8080- Set up the database:
# Create database
createdb spoq
# Run migrations (if available)
sqlx migrate run- Build and run:
cargo build --release
cargo runThe API will be available at http://localhost:8080
- Go to Railway and create a new project
- Choose "Deploy from GitHub repo" or use Railway CLI
- In your Railway project dashboard, click "New"
- Select "Database" → "Add PostgreSQL"
- Railway will automatically create a PostgreSQL instance and set
DATABASE_URL
Add the following environment variables in Railway's dashboard:
| Variable | Description | Example |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Auto-set by Railway Postgres plugin |
GITHUB_CLIENT_ID |
GitHub OAuth App Client ID | abc123def456 |
GITHUB_CLIENT_SECRET |
GitHub OAuth App Secret | secret_xyz789 |
GITHUB_REDIRECT_URI |
OAuth callback URL | https://your-app.railway.app/auth/github/callback |
JWT_SECRET |
Secret for JWT signing (32+ chars) | your-secure-random-string-min-32-chars |
HOST |
Server host | 0.0.0.0 |
PORT |
Server port | 8080 |
- Connect your GitHub repository to Railway
- Railway will automatically detect the Dockerfile
- Push to your main branch to trigger deployment
# Install Railway CLI
npm i -g @railway/cli
# Login
railway login
# Link to project
railway link
# Deploy
railway upOnce deployed, Railway will provide a public URL (e.g., https://your-app.railway.app). Test the deployment:
curl https://your-app.railway.app/
# Expected: "Hello, World!"To enable GitHub authentication, you need to create a GitHub OAuth App:
- Go to GitHub Developer Settings
- Click "New OAuth App"
- Fill in the details:
- Application name: SPOQ Web APIs
- Homepage URL: Your Railway app URL or
http://localhost:8080for development - Authorization callback URL:
https://your-app.railway.app/auth/github/callback
- Click "Register application"
- Copy the Client ID and generate a Client Secret
- Add these to your Railway environment variables or local
.envfile
- GET
/- Returns "Hello, World!" (used for health checks)
- GET
/auth/github- Initiate GitHub OAuth flow - GET
/auth/github/callback- OAuth callback handler - POST
/auth/logout- Logout user
- All authenticated routes require
Authorization: Bearer <jwt_token>header
spoq-web-apis/
├── src/
│ └── main.rs # Application entry point
├── Cargo.toml # Rust dependencies
├── Dockerfile # Multi-stage Docker build
├── railway.toml # Railway configuration
├── .env.example # Environment variables template
└── README.md # This file
cargo testcargo build --releaseThe optimized binary will be in target/release/spoq-web-apis
# Build image
docker build -t spoq-web-apis .
# Run container
docker run -p 8080:8080 --env-file .env spoq-web-apisAll configuration is done via environment variables. See .env.example for a complete list.
The railway.toml file configures deployment behavior:
- Dockerfile-based builds
- Health check on
/endpoint - 30-second health check timeout
- Automatic restart on failure (max 3 retries)
- JWT Secret: Use a strong, random secret (32+ characters)
- HTTPS: Always use HTTPS in production (Railway provides this automatically)
- Environment Variables: Never commit
.envfiles or secrets to git - Rate Limiting: Built-in rate limiting to prevent abuse
- Password Hashing: Argon2 for secure password storage
Railway automatically assigns a PORT environment variable. The app is configured to use port 8080 by default.
Ensure DATABASE_URL is properly set. Railway's PostgreSQL plugin sets this automatically.
Check Railway build logs. Common issues:
- Missing dependencies in Dockerfile
- Cargo.lock conflicts (delete and rebuild)
- Out of memory (increase Railway plan)
The health check pings / endpoint. Ensure:
- App starts within 30 seconds
- Port 8080 is exposed
- No blocking operations in startup
MIT
For issues and questions, please open an issue on GitHub.