Skip to content

Instantly share code, notes, and snippets.

@lasseebert
Created April 14, 2018 20:17
Show Gist options
  • Save lasseebert/d6c1dc229823d99d430b0bf166ee2d72 to your computer and use it in GitHub Desktop.
Save lasseebert/d6c1dc229823d99d430b0bf166ee2d72 to your computer and use it in GitHub Desktop.

Mini project specification

Task

Build a URL shortener API

Requirements

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.

Notes

  • 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.

Ideas for optional 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.

Example requests for both endpoints:

Shorten a 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 a short URL redirect:

Request:

GET /abcd

Success response:

Status: 301
Location: "http://someurl.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment