A simple implementation of a popular system design interview question
Copy the .env.example
to .env
, and update the contents:
BASE_URL="http://localhost:3000"
APP_PORT=3000
REDIS_PORT=<RedisPORT>
REDIS_PASSWORD=<RedisPassword>
REDIS_HOSTS="<RedisClusterIPs>"
npm install
npm start
This endpoint accepts POST
, with a payload, with the following parameters:
url
: the original url to be shortened, length must not exceed 1024 characters including the protocols, currently only support HTTP and HTTPSexpiredIn
: the expiration day of the URL, default is90
days.
Example
POST /url/shorten
{
'url': 'https://github.com/maximmai/url-shortener/edit/main/README.md'
}
Response:
200
{
'url': 'https://fastdns.io/CKRM639'
}
This endpoint accepts a shortened URL, and responds with the original URL, with a HTTP header rewrite to redirect.
Example
GET <shortened_url>
Response:
200 None