Skip to content

A simple implementation of a popular system design interview question

License

Notifications You must be signed in to change notification settings

maximmai/url-shortener

Repository files navigation

url-shortener

A simple implementation of a popular system design interview question

Design

image

Development

Configure the runtime variables

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>"

Running the application

npm install
npm start

APIs

Create an URL

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 HTTPS
  • expiredIn: the expiration day of the URL, default is 90 days.

Example

POST /url/shorten

{
  'url': 'https://github.com/maximmai/url-shortener/edit/main/README.md'
}

Response:

200
{
  'url': 'https://fastdns.io/CKRM639'
}

Retrieve an URL

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

About

A simple implementation of a popular system design interview question

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published