URLShortner(TinyURL) API - Design and implement URL shortening service, service that takes long url and generates short and unique url. Tiny url is extremely handy and less error prone to share through sms/slack/tweets.
- Returns a URL that is shorter than the original.
- Must store the original URL.
- Newly generated URL must be able to link to the stored original.
- Shortened URL should allow redirects.
- Must support custom short URLs.
- Must support many requests at once.
- User can create TinyUrl for the original/source URL
- Users can create CustomUrl for the original/soruce URL
- User are redirected to the original/source url by providing TinyUrl link
- User are redirected to the original/source url by providing CustomUrl link
Spring Boot
MySQL
Google Guava Library
1. POST /tinyurl/create --- Create a shortURL for the original/source URL.
2. POST /tinyurl/create --- Creates a shortURL and custom URL for the original/source URL (by providing customUrl in the Request Body).
3. GET /tinyurl/{shortUrl} --- Redirects to the original URL by getting shortURL.
4. GET /tinyurl/{shortUrl}/{customUrl} --- Redirects the original URL by providing shortUrl and customUrl.
- Clone the git Repo.
- Use ID Intellij/STS/Eclipse.
- Setup MySql DB. - Both Server and client MySqlWorkbench
- Run the script to setup db locally (/src/main/resources/setupdb.sql).
- Modify application.properties as per your db.
- Start SpringBoot application on port 8080.
mvn clean install --settings /{userHome}/tinyURLCraft/tinyURL/
646D
settings.xml
Start SpringBoot application on port 8080. (start application directly using IDE or command prompt: mvn spring-boot:run application name)
-
Use Postman/ Browser.
-
Set Content-type: application/json.
-
Provide Json Request Body for the POST requests.
-
POST /tinyurl/create - Creates TinyUrl for the sourceUrl
URL: http://localhost:8080/create
RequestBody:
{
"sourceUrl": "https://www.google.com"
}
Response: A TinyUrl gets created by giving complete path.
- POST /tinyurl/create : Creates Custom URl
URL: http://localhost:8080/tinyurl/create
RequestBody: {
"sourceUrl": "https://www.amazon.com",
"customUrl": "amazon1"
}
Response: A TinyUrl and CustomUrl gets generated by giving complete Path
- GET /tinyurl/{shortnerid}
Open Postman / Browser and provide the shortURL
GET http://localhost:8080/tinyUrl/{shortUrl}
Response: User gets redirected to the original sourceUrl
on Error: Respective error messages shown to the user
- GET /tinyurl/{shortnerid}/{customid}
Open Postman / Browser and provide the customURL
GET http://localhost:8080/tinyurl/{shorturl}/{customurl}
Response: User gets redirected to the original sourceUrl
on Error: Respective error messages shown to the user
- install locust locally (https://docs.locust.io/en/0.12.2/installation.html)
- Modify src/resources/locustfile.py for valid inputs
- Open a terminal and run the command $locust --host="http://localhost:8080" --locustfile locustfile.py
- Open Browser http://0.0.0.0:8089/ - users can provide inputs (No of Users: 100, Spawn Rate: 1, host: http://localhost:8080)