This is a solution to the URL shortener project on roadmap.sh : https://roadmap.sh/projects/url-shortening-service
This is a simple URL Shortener API built using Java and Spring Boot. It allows users to shorten long URLs and retrieve the original URLs when needed.
The application is live and can be accessed at: Live URL Shortener
- Shorten a long URL
- Retrieve original URL using the shortened URL
- Update and delete shortened URLs
- Retrieve URL statistics
- Simple and efficient
- Java 17
- Spring Boot
- MongoDB
- Swagger for API documentation
To run the project locally, clone the repository and ensure you have Java, Maven, and MongoDB installed.
- Clone the repository:
git clone <repo-url> cd url-shortener-java
- Set up MongoDB:
- Make sure MongoDB is running.
- Update
application.propertiesorapplication.ymlwith your own MongoDB URI. - If running locally, use the default port (27017) or specify your own.
- Build and run the application:
mvn spring-boot:run
- Access the API at
http://localhost:8080/(or your configured port).
- src/main/java/com/example/urlshortener/
- controller/
- UrlController.java
- HomeController.java
- service/
- repository/
- model/
- config/
| Method | Endpoint | Description |
|---|---|---|
POST |
/shorten |
Shorten a URL |
GET |
/shorten/{shortCode} |
Resolve a short URL |
PUT |
/shorten/{shortCode} |
Update a long URL |
DELETE |
/shorten/{shortCode} |
Delete a short URL |
GET |
/shorten/{shortCode}/stats |
Retrieve history of a short URL |
GET |
/swagger-ui/ |
View API documentation |
Feel free to contribute by forking the repo, making changes, and submitting a pull request!