A lightweight URL shortener service built in Zig using the standard library HTTP server.
- Shorten URLs with auto-generated Base62 codes
- Custom short codes support
- Click count tracking
- URL validation (http/https only)
- Reserved word protection
- Zig 0.14.1
git clone https://github.com/mrwormhole/zhortify.git
cd url-shortener
zig run main.zigThe server will start on http://localhost:3000
| 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 |
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"
}Redirects to the original URL and increments click count.
Response: HTTP 301 redirect
Get statistics for a short URL.
Response:
{
"original_url": "https://example.com",
"short_code": "G8",
"click_count": 42,
"created_at": 1749861651
}List all shortened URLs with statistics.
Response:
[
{
"original_url": "https://example.com",
"short_code": "G8",
"click_count": 42,
"created_at": 1749861651
}
]Run the included smoke test to verify all functionality:
chmod +x smoke.sh
./smoke.sh- Length: 3-20 characters
- Allowed characters: letters, numbers, hyphens, underscores
- Reserved words:
api,stats,admin,www,app,short,url,list - Must start with
http://orhttps:// - Maximum request body size: 1MB
- Persistent storage (SQLite)
- Rate limiting
- URL expiration/TTL
- Bulk URL operations
- Docker containerization
- Configuration file support
- Full CORS support