url-shortener

Description

This is a simple URL shortener project built in Java. It uses Javalin to handle REST requests. It stores information about URLs in a database. You can currently choose between SQLite, MySQL and MongoDB.

There is also a frontend that is made with Svelte.

Usage

Users are required to have an account before they can create urls. They will receive an JWT token after logging in.

Register

curl --location 'http://localhost:8020/api/auth/register' \
--header 'Content-Type: application/json' \
--data '{"username": "YOUR_NAME", "password": "YOUR_PASSWORD"}'

Login

curl --location 'http://localhost:8020/api/auth/login' \
--header 'Content-Type: application/json' \
--data '{"username": "YOUR_NAME", "password": "YOUR_PASSWORD"}'

Shortening a URL

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:8020/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

{"url":"tQYC5b"}

Retrieving URL Information

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 tQYC5b with the actual short URL code.

curl --location 'http://localhost:8020/api/stats/tQYC5b'

The response will look like this

{"original_url":"https://www.youtube.com/watch?v=dQw4w9WgXcQ","redirects":0,"shortened_url":"tQYC5b"}

Accessing Shortened URLs

Once a URL is shortened, you can access it using the shortened URL, for example:

http://localhost:8020/tQYC5b

Frontend

To launch the frontend run the following command in the frontend directory

npm run dev -- --open

Screenshots

License

This project is licensed under the Unlicense

Top categories

svelte logo

Want a Svelte site built?

Hire a Svelte developer
Loading Svelte Themes