An asynchronous backend sandbox built to master production-grade web services in Rust.
- Thread-Safe State & Static Keys: Sharing DB pools via
Arc<AppState>and lazy initializing crypto keys withstd::sync::LazyLock. - Type-Safe Extraction & RBAC: Extracting Bearer tokens via
TypedHeaderintoClaimspaired with role-matching middleware (require_role). - Socketless Integration Testing: Testing the HTTP pipeline in-memory via
tower::Service(oneshot/call) using an ephemeralsqlite::memory:database. - Defensive Traffic Control: Layering Tower middleware for global rate-limiting (
GovernorLayer), timeouts (TimeoutLayer), and concurrency limits. - Declarative Payload Validation: Binding the
validatorcrate to deserialization pipelines to sanitize input data before hitting domain logic.
- Rate Limiting:
GovernorLayer(2 req/sec, burst 5) via client IP. - Timeouts:
TimeoutLayer(10-second limit). - Observability:
TraceLayerstructured metrics.
| Method | Endpoint | Description | Extractors / Middleware |
|---|---|---|---|
| GET | / |
Root Index | None |
| GET | /pages |
Query-driven list pagination | Query<Pagination> |
| POST | /login |
Authenticate 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 | JWT (Claims) + Path<u64> + Json<UpdateUser> + Concurrency Limited |
| DELETE | /users/delete/{id} |
Remove a user by ID | JWT (Claims) + Path<u64> + Concurrency Limited |
| GET | /users/greet/{name} |
Dynamic path injection | Path<String> + Concurrency Limited |
| GET | /admin/list |
Fetch all users | JWT (Claims) + Query<Pagination> + Admin Role |
| PATCH | /admin/{id}/role |
Modify user role level | JWT (Claims) + Path<u64> + Json<ChangeRolePayload> + Admin Role |
| ANY | /assets/* |
Static asset / SPA fallback | ServeDir / ServeFile ("public") |
JWT_SECRET=your_super_secret_key_here# Automatically builds SQLite schema and listens at http://localhost:3000
cargo runcargo test