Skip to content

dharmateja03/URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener Service

A simple URL shortener API built with Go, featuring PostgreSQL storage, rate limiting, and API key authentication.

Features

  • Shorten long URLs to 6-character codes
  • PostgreSQL database storage
  • Rate limiting (10 req/sec, burst of 20)
  • Simple API key authentication
  • Docker deployment
  • Health check endpoint

API Endpoints

Shorten URL

POST /shorten
Headers: X-API-Key: your-secret-api-key
Body: {"url": "https://example.com"}
Response: {"short_url": "http://localhost:8080/abc123", "code": "abc123"}

Redirect

GET /{code}
Response: 301 redirect to original URL

Health Check

GET /health
Response: {"status": "healthy"}

Quick Start

  1. Run with Docker Compose:

    docker-compose up --build
  2. Test the API:

    # Shorten a URL
    curl -X POST http://localhost:8080/shorten \
      -H "X-API-Key: your-secret-api-key" \
      -H "Content-Type: application/json" \
      -d '{"url": "https://google.com"}'
    
    # Use the short URL (replace abc123 with actual code)
    curl http://localhost:8080/abc123

Environment Variables

  • DATABASE_URL: PostgreSQL connection string
  • API_KEY: Authentication key for /shorten endpoint
  • BASE_URL: Base URL for generated short links
  • PORT: Server port (default: 8080)

Development

# Install dependencies
go mod tidy

# Run locally (requires PostgreSQL)
go run main.go

About

This repo contains URL-Shortner Developed Using GoLang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published