This is a microservice built with SpringBoot and MongoDB.
- Clone this repository to your local machine:
git clone https://github.com/chatgut/URL-Shortener-Service.git
- Navigate to the project directory:
cd url-shortener-service
- Start the application using Docker Compose:
docker-compose up
- You are now done! Once Docker Compose has started the containers, you can access the application at
http://localhost:8080
.
The application is configured to connect to MongoDB using the following URI:
mongodb://mongo:27017/urlshortener
If you need to customize the MongoDB connection settings, you can update the SPRING_DATA_MONGODB_URI
environment variable in the docker-compose.yml
file.
To shorten a URL, send a POST request to the /urls/create
endpoint with the original URL in the request body.
JSON Body:
{
"originalUrl": "http://example.com"
}
Example Output:
{
"id": "664ba4785b64a14ee2d09a26",
"originalUrl": "http://example.com",
"shortUrl": "2edf5e51",
"createdAt": "2024-05-20T19:28:56.447953337"
}
http://localhost:8080/urls
To redirect to the original URL, send a GET request to the /urls/{shortUrl}
. Replace {shortUrl}
with the "shortUrl", example 2edf5e51
.
To remove URL from DB, send DELETE request to /urls/remove/{id}
. Replace {id}
with the related "id", example 664ba4785b64a14ee2d09a26
.