This is a simple URL shortener service built with Kotlin and Micronaut. It allows users to shorten long URLs and retrieve the original URLs using the shortened version.
The service generates a unique identifier for each URL. The ID is generated by DB. The current implementation stores the generated short URL in postgres.
- Clone the repository.
- Navigate to the project directory.
- Run the application:
docker compose up -d ./gradlew run
NOTE: There is a deprecation warning when running the application with ./gradlew run. Due to having time constraints, I did not have time to fix it.
There are two endpoints available:
POST /api/v1/shortened-urls: Shorten a URLGET /api/v1/shortened-urls/{shortUri}: Retrieve the original URL
See the API Docs for more details.
The implementation assumes that the API is being used by a custom frontend application, which will handle the redirection to the original URL.
The response type of the endpoints is JsonApi.
curl --location 'http://localhost:8080/api/v1/shortened-urls' \
--header 'Content-Type: application/json' \
--data '{"url": "https://google.com/test"}'Make sure to replace {shortUri} with the short URI generated by the service.
curl --location 'http://localhost:8080/api/v1/shortened-urls/{shortUri}'There's a scheduled job to delete URLS that have been created before a specific date,
specified in app.prune.time-in-seconds configuration.
Tests use a postgres test container. Make sure to have docker installed.
- Run the tests:
./gradlew test
- Stop the application:
- Remove DB container:
docker compose down -v
This is a simple implementation and is not intended for production use.
- Add validation for the input URL.
- Add error handling.
- Make sure the generated short URL is URL safe.
- Enhance short URL generation algorithm to be more efficient and generate more user-friendly URLs.
- Enhance API docs with swagger-ui.
- Add logging, metrics, and monitoring.
- Add security features, including rate-limits, etc.
MIT License