Skip to content

Howard-nolan/URL-Shortener

Repository files navigation

OpenAPI

Go URL Shortener

A high performance URL shortener written in Go to explore distributed systems fundamentals: observability, scalability, deployment, and testing.

👉 I document what I learn from each pull request in LEARNINGS.md.


At a glance

  • REST API built with chi, request timeouts, and graceful shutdown.
  • SQLite persistence with embedded Goose migrations; data stored in data/app.db.
  • In-memory LRU cache for hot redirect lookups.
  • Idempotent create flow when clients reuse X-Request-ID.
  • Observability: Zap JSON logs, Prometheus metrics at /metrics, and a local Grafana stack.
  • Testing: table-driven unit tests with sqlmock plus integration tests via httptest.

Quick Start

Run the server:

go run ./cmd/server

Override the port:

PORT=9090 go run ./cmd/server

API

Endpoints:

Method Endpoint Description Status / Utility
POST /shorten Create a shortened URL from a long link Core API
GET /r/{code} Redirect to the original destination Core API
GET /metrics Prometheus metrics for monitoring DevOps
GET /health Liveness probe (Server is alive) Kubernetes/Health
GET /readyz Readiness probe (DB is connected) Kubernetes/Health

Example:

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

Response:

{"short":"http://localhost:8080/r/abc123"}

Full OpenAPI spec: api/openapi.yaml

Observability

Start the containerized service (URL Shortener + Prometheus + Grafana):

docker compose up

Tests

Run unit tests:

go test ./...

Run integration (black-box) tests:

go test -tags=integration ./...

About

A high performance URL shortener written in Go to explore distributed systems fundamentals: observability, scalability, deployment, and testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors