Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 2.14 KB

README.md

File metadata and controls

78 lines (60 loc) · 2.14 KB

URL Shortener API

CI

A lightweight REST API for shortening URLs, built with Java, Gradle, and Javalin. Includes an automated test suite and a CI pipeline via GitHub Actions.

Features

  • Shorten a long URL into a random 6-character code
  • Redirect from the short code to the original URL
  • Track visit counts per short URL
  • In-memory storage (no database required) — keeps the project focused on build automation and CI/CD rather than persistence

Tech Stack

  • Java 17
  • Gradle (via the Gradle Wrapper — no local Gradle install required)
  • Javalin — lightweight web framework
  • Jackson — JSON serialization
  • JUnit 5 — testing
  • GitHub Actions — CI, runs the full test suite on every push

Getting Started

Prerequisites

  • JDK 17 or later

Run the server

./gradlew run

Server starts on http://localhost:7000.

Run the tests

./gradlew test

API Endpoints

Method Endpoint Description
GET /health Health check, returns OK
POST /shorten Shortens a URL. Body: {"url": "https://example.com"}
GET /{code} Redirects to the original URL
GET /stats/{code} Returns visit count and original URL for a code

Example

curl -X POST http://localhost:7000/shorten \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.google.com"}'

Response:

{
  "code": "aZ3kQ1",
  "shortUrl": "http://localhost:7000/aZ3kQ1",
  "originalUrl": "https://www.google.com"
}

CI/CD

Every push and pull request triggers a GitHub Actions workflow that builds the project and runs the full test suite on a clean environment. See .github/workflows/ci.yml.

Project Structure

app/
├── src/main/java/javagradleapp/
│   ├── App.java            # Server setup and routes
│   ├── UrlEntry.java        # Data model for stored URLs
│   └── ShortenRequest.java  # Request body shape
└── src/test/java/javagradleapp/
    └── AppTest.java         # Automated tests