This is a simple URL shortener project built in Spring Boot using a PostgreSQL database.
There is also a frontend that is made with Svelte.
Users are required to have an account before they can create urls. They will receive an JWT token after logging in.
curl --location 'http://localhost:8080/api/auth/register' \
--header 'Content-Type: application/json' \
--data '{"username": "YOUR_NAME", "password": "YOUR_PASSWORD"}'
curl --location 'http://localhost:8080/api/auth/login' \
--header 'Content-Type: application/json' \
--data '{"username": "YOUR_NAME", "password": "YOUR_PASSWORD"}'
This command sends a POST request to the /api/create
endpoint with the original URL as JSON data. The server will generate a short URL for the provided URL.
curl --location 'http://localhost:8080/api/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_TOKEN_HERE' \
--data '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}'
The response will look like this
{
"id": "Xb1W8",
"originalUrl": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"redirectCount": 0,
"userId": "bfc08eb7-b350-45b9-a31c-42cdd25de670"
}
This command sends a GET request to the /api/stats/{code}
endpoint, where {code}
represents the short URL code. The server will return information about the URL, including the original URL and the number of redirects.
Make sure to replace Xb1W8
with the actual short URL code.
curl --location 'http://localhost:8080/api/stats/Xb1W8'
The response will have the same format as the response of the /create
endpoint above.
Once a URL is shortened, you can access it using the shortened URL, for example:
http://localhost:8080/Xb1W8
To launch the frontend run the following command in the frontend directory
npm run dev -- --open
This project is licensed under the Unlicense