Webby is an asynchronous backend sandbox built to master building web services in Rust using Axum, Tokio, and Tower. It serves as a hands-on laboratory for managing shared state, integrating databases, and writing custom type-safe middleware.
- Language & Framework: Rust + Axum
- Runtime & Ecosystem: Tokio + Tower + Tower-HTTP
- Database & Configuration: Toasty ORM (SQLite) + Dotenvy
- Security & Crypto: JSON Web Tokens (
jsonwebtoken) + Argon2 Password Hashing (argon2)
- State & DB Management: Thread-safe database connection sharing via
Arc<AppState>using the Toasty ORM against SQLite. - JWT Authentication & RBAC: Custom
FromRequestPartsextractor to decode, validate, and secure routes using JSON Web Tokens (HS256), paired with Role-Based Access Control middleware. - Cryptographic Password Hashing: Secure password management using the Argon2 hashing algorithm with automated salt generation via
OsRng. - Traffic Control & Middleware: Structured logging (
TraceLayer), request timeouts (TimeoutLayer), concurrency bounds (ConcurrencyLimitLayer), and rate limiting (GovernorLayer). - Input Validation & Errors: Chaining the
validatorcrate into the Axum pipeline and transforming internal app logic into structured HTTP responses via customIntoResponseenums. - SPA Routing: Serving physical assets with
ServeDirand catching unmatched traffic with anindex.htmlfallback. - Graceful Shutdowns: Listening for cross-platform OS signals (
SIGINT/SIGTERM) to drop the runtime safely.
| Method | Endpoint | Description | Auth / Extractors / Middleware |
|---|---|---|---|
| GET | / |
Root Index | None |
| GET | /pages |
Query-driven list pagination | Query<Pagination> |
| POST | /login |
Authenticate user and issue JWT | Json<AuthPayload> |
| GET | /users |
User section about | Concurrency Limited (Max 5) |
| POST | /users/create |
Validate and insert new user | Json<CreateUser>, Concurrency Limited |
| PATCH | /users/update/{id} |
Update user profile | Requires JWT (Claims), Path<u64>, Json<UpdateUser> |
| DELETE | /users/delete/{id} |
Remove a specific user by ID | Requires JWT (Claims), Path<u64>, Concurrency Limited |
| GET | /users/greet/{name} |
Dynamic path injection | Path<String>, Concurrency Limited |
| GET | /admin/list |
Asynchronously fetch all users | Requires JWT (Claims) + Admin Role Middleware |
| ANY | /assets/* / Fallback |
Static asset server / SPA catch-all | ServeDir + ServeFile |
JWT_SECRET=your_super_secret_key_here# Automatically builds SQLite schema and listens at http://localhost:3000
cargo runJWT_SECRET=test_secret cargo test