Skip to content

Simple URL shortener service implemented in Go. This repo contains a small HTTP API to shorten URLs and redirect short codes to original URLs. The service uses an in-memory storage implementation and is packaged with Docker and Docker Compose.

Notifications You must be signed in to change notification settings

jaki729/URL_Shortener_App-Task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener - TASK — README

Simple URL shortener service implemented in Go. This repo contains a small HTTP API to shorten URLs and redirect short codes to original URLs. The service uses an in-memory storage implementation and is packaged with Docker and Docker Compose.

Quick links (workspace)

Requirements

  • Docker & Docker Compose
  • (Optional) Go 1.24 or newer for running tests locally (module set in go.mod)

How to run the code

  1. Run with Docker Compose (recommended)
  • Build and start (background):
docker compose up --build -d
  • Check container logs:
docker compose logs -f app
  • Stop and remove:
docker compose down

Notes:

  1. Run locally (without Docker)
  • With Go installed (recommended for development):
# from repo root
go run ./cmd/server
# or build binary
go build -o urlshort ./cmd/server
./urlshort
  1. Run tests
  • Locally (requires Go toolchain):
go test ./... -v

Tests are in test/service_test.go and test/handler_test.go.

  • Inside a container (no local Go):
docker run --rm -v "$(pwd):/app" -w /app golang:1.24 go test ./... -v
  1. Manual / API testing (curl or Postman)
  • Shorten a URL (POST):
curl -s -X POST -H "Content-Type: application/json" \
  -d '{"url":"https://example.com"}' \
  http://localhost:8080/api/shorten
# -> {"short_url":"http://localhost:8080/EAaArVRs","long_url":"https://example.com"}
  • Inspect redirect headers (HEAD):
curl -I http://localhost:8080/<shortCode>
# -> HTTP/1.1 302 Found, Location: https://example.com
  • Follow redirect (GET):
curl -L http://localhost:8080/<shortCode>

Postman:

  • Create environment variable base_url = http://localhost:8080.
  • POST {{base_url}}/api/shorten with JSON body { "url": "https://example.com" }.
  • For redirect request GET {{base_url}}/{{short_code}} — disable auto-follow redirects to inspect the 302 Location header.

Behavior summary

About

Simple URL shortener service implemented in Go. This repo contains a small HTTP API to shorten URLs and redirect short codes to original URLs. The service uses an in-memory storage implementation and is packaged with Docker and Docker Compose.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published