Part 8: Backend¶
This part builds a small web service in six steps. You will read an HTTP request by hand, store rows in SQLite, hash passwords and sign tokens, check input, put it together in a REST service, and then give that service layers, a database, and token protection. The first lessons use only the standard library, and the last two add FastAPI. Work through the lessons in order.
- How an HTTP request reaches your code and comes back: Parse a request, route it, and send a status code and body with
http.server. ~20 min - Storing and changing rows with SQLite: Create, read, update, and delete rows safely with placeholders and commits. ~20 min
- Hashing passwords and signing tokens: Store salted
scrypthashes and build HMAC-signed tokens with expiry. ~25 min - Checking input and wrapping handlers in middleware: Collect validation errors and wrap handlers in reusable middleware. ~25 min
- A small notes REST service with FastAPI: Serve notes with FastAPI, return the right status codes, and test the routes with
TestClient. ~30 min - A URL shortener with layers, SQLite, and bearer tokens: Split a service into routes, service, and storage layers, store rows in SQLite, protect routes with tokens, and paginate. ~45 min