Skip to content

Instantly share code, notes, and snippets.

@aneeskodappana

aneeskodappana/test.md

Last active Apr 12, 2021
Embed
What would you like to do?
coding test

Task: URL shortener

Time limit : 3-4 Hour

Problem

Design a URL shortener service like (bit.ly). this service will provide short aliases redirecting to long URLs and also add the ability to attach tags to URLs.

For example, if we shorten this page through the service: https://example.com/assets/category_B/subcategory_C/Foo/ We would get: http://localhost:80/tiny/ju7gkp

Objectives

  • To evaluate best practices in code organization and implementation of design patterns
  • To evaluate relational database design skill
  • To evaluate the understanding of REST conventions

Database design

  • you can use any relational database (SQLite, MySQL, PostgreSQL).
  • define a many-to-many relationship between URLs and tags.

Create three API endpoints

1. POST /short

payload:

{
    "url": "https://example.com/assets/category_B/subcategory_C/Foo/",
    "tags": ["Wiki", "Foo"]
}

response

{
    "statusCode": 201,
    "message": "Created"
}

2. GET /urls

response

[
    {
        tags: ["Wiki", "Foo"],
        url: "http://localhost:80/tiny/ju7gkp"
    },
    {
        tags: ["Readlist"],
        url: "http://localhost:80/tiny/bh8jwx"
    }
]

3. GET /urls?tag=Wiki

response

[
    {
        tags: ["Wiki", "Foo"],
        url: "http://localhost:80/tiny/ju7gkp"
    },
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment