Task: URL Shortener

Tags

Microservice, Backend

Description

You know what is this about! This question is used thousands of times in design interviews. Here's the chance of actually doing it!

Specification

Configuration

configSource: "env"

# The server should start at this port
PORT=8080

If you use docker or docker-compose, this is the env used inside the container.

The server has the following endpoints.

POST /generate

The URL will be passed as a string in the HTTP request's body.

Returns a plain/text response with the shortened relative URL.

GET /follow/<short-url>

short-url is a URL generated from /generate .

If the short-url is invalid, returns a 404.

Otherwise, the response should be a 301 or 302 with the expected original URL.

Notes

Do not try to call external service since your server will not have Internet service, in this task's setup.

Example

$ curl -X POST -H "Content-Type: text/plain" -d 'https://www.google.com' 'http://localhost:8080/generate'
1

$ curl -I 'http://localhost:8080/follow/1'
HTTP/1.1 302 Found
X-Powered-By: Express
Location: https://www.google.com
Vary: Accept
Content-Type: text/plain; charset=utf-8
Content-Length: 44
Date: Tue, 23 Jul 2019 21:01:54 GMT
Connection: keep-alive
Instructions
Get started
My Submissions

Submit to see your result!

Leaderboard

Nobody here yet, solve it now to get on the board!