This project implements a URL shortener service that generates a unique 6-character string for each provided URL. It includes both frontend and backend components, implemented with custom functions instead of relying on npm packages for URL shortening. Designe: from Dribble
Custom Functions
Instead of using existing npm packages, custom functions were implemented to handle URL shortening. These functions optimize for both average and worst-case time complexities.
To generate unique short URLs, a custom function (getUniqueShortUrl) was implemented. This function ensures that each generated short URL is unique for every provided URL. While npm packages are available for this purpose, custom implementation allows for tailored control and optimization specific to project requirements.
For validating URLs, a custom function (isValidUrl) is used. This function checks whether a given URL is valid based on a set of criteria defined within the project scope. This approach ensures that only valid URLs are accepted and shortened.
-
getUniqueShortUrl:
Average Case: O(1) Worst Case: O(n)
-
isValidUrl:
Average Case: O(1) Worst Case: O(n)
-
Frist clone this repo
https://github.com/anikakash/Shortly.git
-
Navigate to
backend
andfrontend
folder and then rumnpm install
in both directory.
http://localhost:5173
-
URL Shortner:
api end point : http://localhost:8000/api/shortner Method: Post request Body: { "originalUrl" : "your url" }
-
Redirect URL:
api end point : http://localhost:8000/api/:id Method: GET
Response:
For testign purpose i haven't use .env file to hide rensative url of my db and secrite key.