Build a URL shortener API
The following endpoints must be implemented:
- Shorten a URL:
POST /urls
- Request a short url redirect:
GET <short_url>
No HTML frontend is required, only these two endpoints.
See example requests and responses below.
- The task is very open; architecture and implementation details are up to you :)
- Try to write the mini project as you would for a production system, since the example code will then more accurately reflect your coding style, choices and skillset.
- Spend a maximum of around two hours on it. This is just for your own sake so you don't spend all your free time on it.
- If you wish to add features other that those in the requirements, feel free to do so. It is totally fine to only implement the requirements.
You will not be judged on how many of these are implemented. Zero is really fine ;)
These are just ideas. If you think something else could be fun to implement, feel free to do so.
- Persist shortened URLs between application restarts
- Cache shortened URLs (if persisted) for faster redirects
- Expire shortened URLs after a time period
- Performance optimize for many simultaneous requests
- Save statistics for a shortened URL
- Expose statistics via a new endpoint
- Handle duplicate URLs by returning the same shortened URL.
Request:
POST /urls
Content-Type: application/json
{"url": "http://someurl.com"}
Success response:
Status: 201
Content-Type: application/json
{
"url": "http://someurl.com",
"short": "/abcd"
}
Request:
GET /abcd
Success response:
Status: 301
Location: "http://someurl.com"