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
- State & DB Management: Thread-safe database connection sharing via
Arc<AppState>using the Toasty ORM against SQLite. - JWT Authentication: Custom
FromRequestPartsextractor to decode, validate, and secure routes using JSON Web Tokens (HS256). - 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 (2s delay) | Concurrency Limited (Max 5) |
| GET | /users/list |
Asynchronously fetch all users | Requires JWT (Claims) |
| POST | /users/create |
Validate and insert new user | Json<CreateUser>, Concurrency Limited |
| 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 |
| 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