An AI Agent Wrote a URL Shortener in 17 Lines. I Tested It With Real Requests.
A URL shortener sounds like a weekend project, so I had an AI agent write one in plain Node with zero packages, then tested it with real requests. Here is what works, what the tests caught, and what I would fix before putting it online.
The build
The whole server is 17 lines. One route takes a URL and returns a random 6-character code. Another route looks the code up and redirects. Codes use letters and numbers with the lookalike characters removed, and the server retries if a generated code already exists.
The real requests
I sent a normal link and got back a short code. Opening that code returned a 302 redirect to the original page, and the stats route then reported one hit. So far, so good.
The part I care about most is validation. I sent a link that starts with javascript: and the server rejected it with a 400. Only HTTP and HTTPS links are allowed. Without that check, a shortener becomes a tool for hiding harmful links behind a trusted-looking domain.
The automated tests
I ran the five automated tests that came with the build:
- Creating a code
- Rejecting a bad link
- Rejecting broken JSON
- Redirecting and counting hits
- An unknown code returning 404
All five passed on the first run. Honest caveat: that is a small test suite, not proof the thing is production ready.
What is missing
- Links live in memory. A restart erases every short link ever created. A database comes first for real use.
- No login and no rate limit. Anyone can create unlimited links.
- No custom names. You get the random code you are given.
As a learning project it is solid. The validation being there at all, and actually working, puts it ahead of most weekend shorteners.
The full build, the code on screen, and all the test runs are in the video:
We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.