A URL Shortener
A working URL shortener, built the way this guide builds everything: no framework, no driver, no dependency that hides the interesting part. The Postgres client is written here, speaking the wire protocol from the cookbook recipe. The slug logic and the HTTP routes are pure functions over bytes, which is why most of these chapters run in your browser. The last chapter assembles the pieces into one file you run against a real database on your machine.
This project is a teaching build, for demonstration on your own machine. Do not deploy it as a public service: it quotes values into SQL instead of using protocol parameters, speaks cleartext auth on loopback, serves one request at a time, and issues guessable slugs. Each chapter names its shortcut where it takes it.
- A database driver is a client library you can write: connect, authenticate, send SQL, read rows, all as messages over one socket.
- A failed query does not cost you the connection. Postgres reports the error and returns to ready, and a client that reads both keeps going.
- A short link is base62 arithmetic on the row id, not a random string you have to check for collisions.
- Handlers that take request bytes and return response bytes need no server to be tested, and the same store seam that made the ORM testable works on a web service.
5 chapters.
- What We Are BuildingA URL shortener with real storage, and the two decisions that shape every chapter after this one.
- A Postgres ClientStartup, password auth, a row iterator and error recovery, tested against scripted bytes.
- Slugs Are ArithmeticBase62 over the row id, and the validation that keeps a redirect service honest.
- Routes Over a SeamAll five CRUD routes as one pure function, tested against an in-memory store.
- The ServerThe client, the slugs and the routes assembled into one file, run against a real Postgres.