Skip to content

Fatemasaifyy/URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener with Analytics

Overview

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.

Features

  • POST /api/urls to create a short link (with optional custom alias + TTL days).
  • GET /api/urls to 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.

Technologies

  • 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

Steps to install & run

# 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:run

Visit http://localhost:8080/ in the browser, submit a long URL, and the page will show the generated alias plus existing entries.

Optional Separate Frontend

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:5173

Make 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.

Testing

$env:JAVA_HOME="C:\Program Files\Eclipse Adoptium\jdk-25.0.1.8-hotspot"
.\mvnw.cmd test

The suite covers:

  • UrlShorteningServiceTest – pure unit tests for alias creation and duplicate handling
  • UrlShortenerControllerTest – MockMvc tests for REST + redirect flow
  • UrlShortenerApplicationTests – basic Spring Boot context boot check

Screenshots

-Model Overview

image

-Services

image

-Control panel

image
  • Notes

  • Storage is in-memory on purpose; it keeps the code approachable. Swap SimpleUrlService with 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.

About

URL Shortener with Analytics using Java and Spring Boot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors