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.
- 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
- 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
- JDK 17 or later
./gradlew runServer starts on http://localhost:7000.
./gradlew test| 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 |
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"
}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.
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