The URL Shortener service is a Springboot web service that shorts any given URL. The created URLs are persisted in a MongoDB collection.
The service exposes two endpoints:
- POST /url-shortener/shortens' to short an URL
- GET /url-shortener/search?url=<shortenedUrl> to retrieve a full URL given its shortened url
Contract and Postman collection can be found in the respective files openapi.yml & url_shortener_collection.json.
- Clone the repository on your computer
$ git clone https://github.com/simonpic/url-shortener
and open it with your preferred IDE.
- To run unit tests
$ ./mvnw test
- To run integration tests
$ ./mvnw verify
Integration tests require Docker as they use testcontainers
To use the application you'll need a MongoDB instance, if you don't have one running on your computer you can launch one with the following command (Docker needed):
$ docker-compose -f docker/stack-dev.yml up
This will start a containerized MongoDB instance, this instance is meant to be used for the development. No volume is mount so data won't persist after the container is stopped.
- To start the URL Shortener service
$ ./mvnw spring-boot:run
- To stop the MongoDB container
$ ./mvnw docker-compose -f stack-dev.yml down
!! Docker required !!
$ make build_and_start
Or
$ ./mvnw spring-boot:build-image
$ docker-compose -f docker/stack.yml up
This will create a buildpack of the springboot application, then launch a docker-compose stack composed by the URL Shortener service and a MongoDB instance.
$ make start_app
Or
$ docker-compose -f docker/stack.yml up
$ make stop_app
Or
$ docker-compose -f docker/stack.yml down