This application allows users to shorten URLs, redirect to the original URL using the shortened version, and view a ranking of the most accessed shortened URLs. It uses Spring Boot for the backend and H2 as an in-memory database.
- Shorten URL: Generate a shortened URL for an original URL.
- Redirect: Redirect from a shortened URL to the original URL.
- Ranking: View the top 10 most accessed shortened URLs.
This endpoint generates a shortened URL for a given original URL. If the URL has already been shortened before, it returns the existing shortened URL.
- Parameters:
url: The original URL to be shortened (e.g.,https://example.com).
- Status: 201 Created
- Body: The original URL and its corresponding shortened URL.
POST /api/create?url=https://example.comResponse:
{
"urlOriginal": "https://example.com",
"urlShort": "https://abc123.com"
}This endpoint redirects from a shortened URL to the corresponding original URL.
- Parameters:
url: The shortened URL to redirect (e.g.,https://abc123.com).
- Status: 200 OK
- Header:
Location: The original URL.
GET /api/find?url=https://abc123.comResponse:
HTTP/1.1 200 OK
Location: https://example.comThis endpoint returns a ranking of the top 10 most accessed shortened URLs.
- Status: 200 OK
- Body: A list of the top 10 most accessed URLs along with the number of times they have been accessed.
GET /api/rankingResponse:
[
{
"url": "https://xyz789.com",
"count": 150
},
{
"url": "https://abc123.com",
"count": 120
}
]- Spring Boot: Framework for building the backend.
- H2 Database: In-memory database for storing URLs and access data.
- SHA-256: For generating unique short URL hashes.
- UUID: To ensure uniqueness in the short URL generation process.
-
Clone the repository:
git clone https://github.com/viniciusmecosta/UrlShort
-
Navigate to the project directory:
cd UrlShort -
Build the project using Maven:
./mvnw clean install
-
Run the application:
./mvnw spring-boot:run
-
The application will be available at
http://localhost:8080.