This is a simple URL shortener service built with Spring Boot. Project details - https://roadmap.sh/projects/url-shortening-service
- Java 21
- Maven 3.6+
-
Clone the repository:
git clone https://github.com/yourusername/url-shortener.git cd url-shortener -
Build the project:
mvn clean install -
Run the application:
mvn spring-boot:run
The application will start on http://localhost:8080.
- POST
/api/shorten - Body:
{ "url": "https://example.com/long/url" }
- GET
/api/shorten/{shortCode}
- GET
/api/{shortCode}
- PUT
/api/shorten/{shortCode} - Body:
{ "url": "https://example.com/new/long/url" }
- DELETE
/api/shorten/{shortCode}
- GET
/api/shorten/{shortCode}/stats
You can use tools like cURL, Postman, or any HTTP client to test the API endpoints.
Example using cURL:
-
Create a short URL:
curl -X POST -H "Content-Type: application/json" -d '{"url":"https://example.com/long/url"}' http://localhost:8080/api/shorten -
Get statistics for a short URL:
curl http://localhost:8080/api/shorten/abc123/stats
The application uses an H2 in-memory database. You can access the H2 console at http://localhost:8080/h2-console with the following details:
- JDBC URL:
jdbc:h2:mem:urlshortener - Username:
sa - Password:
password
Please feel free to submit issues, fork the repository and send pull requests!
This project is licensed under the MIT License.