There would be two kinds of APIs:
That means you give the long form of the URL and expect or sort from the URL.
POST /user/{id}
{
"originalUrl":"",
"type":"custom"
"newUrl":"",
"expiredAt":""
}
The feature for original URL or custom URL would be for premium users. They can pass a new URL and an expired time as well. For the general user, only post call would be with the original URL, and the response would be the new URL with expired time.
POST /user/{id}
{
"originalUrl":""
}
GET /url/{short_url} => would return the original URL with expiration time
Response :
{
"originalUrl":"",
"type":"custom/normal"
"newUrl":"",
"expiredAt":""
}
For the high-level design, what I have thought is:
One of the detailed component designs in the URL shortening service will be how we shorten the URL. One approach would be to use the DB auto increment ID, but that will be the bad approach, the worst approach, so we'll not go ahead with that.
One approach would be that there will be a service that will pass that value, the URL hash, since every URL will be unique. Let's suppose two users come with the same URL, the same kind of URL, so we want them to return a particular URL, right?