Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

mrwormhole/zhortify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zhortify

A lightweight URL shortener service built in Zig using the standard library HTTP server.

Features

  • Shorten URLs with auto-generated Base62 codes
  • Custom short codes support
  • Click count tracking
  • URL validation (http/https only)
  • Reserved word protection

Getting Started

Prerequisites

  • Zig 0.14.1

Installation

  git clone https://github.com/mrwormhole/zhortify.git
  cd url-shortener
  zig run main.zig

The server will start on http://localhost:3000

API Endpoints

Method Endpoint Description
GET / Health check
POST /shorten Create short URL
GET /:code Redirect to original URL
GET /stats/:code Get URL statistics
GET /list List all URLs

POST /shorten

Create a new short URL.

Request Body:

{
  "url": "https://example.com",
  "custom_code": "optional-custom-code"
}

Response:

{
  "short_url": "http://localhost:3000/G8",
  "short_code": "G8"
}

Error Response:

{
  "error_message": "Invalid URL format"
}

GET /:code

Redirects to the original URL and increments click count.

Response: HTTP 301 redirect

GET /stats/:code

Get statistics for a short URL.

Response:

{
  "original_url": "https://example.com",
  "short_code": "G8",
  "click_count": 42,
  "created_at": 1749861651
}

GET /list

List all shortened URLs with statistics.

Response:

[
  {
    "original_url": "https://example.com",
    "short_code": "G8",
    "click_count": 42,
    "created_at": 1749861651
  }
]

Testing

Run the included smoke test to verify all functionality:

  chmod +x smoke.sh
  ./smoke.sh

Configuration

  • Length: 3-20 characters
  • Allowed characters: letters, numbers, hyphens, underscores
  • Reserved words: api, stats, admin, www, app, short, url, list
  • Must start with http:// or https://
  • Maximum request body size: 1MB

Future Improvements

  • Persistent storage (SQLite)
  • Rate limiting
  • URL expiration/TTL
  • Bulk URL operations
  • Docker containerization
  • Configuration file support
  • Full CORS support

About

experimental URL shortener 🦎

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published