A URL shortener built with pure Spring Boot (no database, ORMs, or extra services). Everything lives in-memory using a ConcurrentHashMap, and a single static index.html (served from src/main/resources/static) offers a tiny UI to create, list, and delete short links.
- POST
/api/urlsto create a short link (with optional custom alias + TTL days). - GET
/api/urlsto view all stored links (including hit counts and timestamps). - DELETE
/api/urls/{alias}to remove an entry. - GET
/{alias}performs a plain HTTP 302 redirect and increments hit count. - Friendly HTML page at
http://localhost:8080/built with vanilla JS + fetch. - In-memory storage keeps the code easy to understand—restart equals clean slate.
- Java 17, Spring Boot 4 (web + validation starters only)
- JUnit 5 + Spring Test (MockMvc) for basic coverage
- Maven Wrapper (
mvnw) so no global Maven installation is required
# Ensure Java 17+ is available
$env:JAVA_HOME="C:\Program Files\Eclipse Adoptium\jdk-25.0.1.8-hotspot"
cd D:\URL-Shortener
.\mvnw.cmd spring-boot:runVisit http://localhost:8080/ in the browser, submit a long URL, and the page will show the generated alias plus existing entries.
A tiny standalone UI (plain HTML + lite-server) lives in the frontend/ folder if you prefer running the client separately.
cd D:\URL-Shortener\frontend
npm install # first-time only
npm start # serves http://localhost:5173Make sure the Spring Boot API is already running on port 8080. The frontend calls http://localhost:8080/api/urls, so CORS is enabled in UrlShortenerController.
$env:JAVA_HOME="C:\Program Files\Eclipse Adoptium\jdk-25.0.1.8-hotspot"
.\mvnw.cmd testThe suite covers:
UrlShorteningServiceTest– pure unit tests for alias creation and duplicate handlingUrlShortenerControllerTest– MockMvc tests for REST + redirect flowUrlShortenerApplicationTests– basic Spring Boot context boot check
-Model Overview
-Services
-Control panel
- Storage is in-memory on purpose; it keeps the code approachable. Swap
SimpleUrlServicewith your preferred persistence layer if needed. - Static frontend is intentionally basic HTML/JS so the entire stack stays Java-oriented.
- Static frontend is intentionally basic HTML/JS so the entire stack stays Java-oriented.