How it works
POST /api/url creates a short link backed by Drizzle on D1. Redirects through GET /:shortCode hit a 1-hour KV cache before falling through to the database. Every redirect emits an event to Cloudflare Analytics Engine.
Quick start
Admin endpoints under /api/* require an ES256 JWT in Authorization: Bearer <token>. Create a link:
curl -X POST https://shortener.cdlab.workers.dev/api/url \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"records": [
{ "url": "https://example.com/very/long/path" }
]
}'Response:
{
"code": 0,
"message": "ok",
"data": {
"successes": [
{
"success": true,
"hash": "<sha256-hex>",
"shortCode": "ab12CDef",
"shortUrl": "https://shortener.cdlab.workers.dev/ab12CDef",
"url": "https://example.com/very/long/path",
"expiresAt": 1730000000000
}
],
"failures": []
}
}Then anyone can follow the short link:
curl -I https://shortener.cdlab.workers.dev/ab12CDef
# HTTP/2 302
# location: https://example.com/very/long/pathAPI endpoints
Public 302 redirect. Social-media crawlers are sent to /:shortCode/og for preview rendering.
JSON service health check (DB + Analytics readiness).
Batch create up to 100 links. Each record may include an optional custom hash, userId, expiresAt (epoch ms), or attribute blob.
Batch update up to 100 links by hash; clears the redirect cache.
Batch soft-delete up to 100 links; clears both redirect and OG caches.
Generate a memorable slug via Workers AI (cached 7d in KV). Also: POST /api/ai/batch-slug, GET /api/ai/suggestions.
Aggregate clicks/visitors across all links. Sibling endpoints: /timeseries, /top-countries, /top-referrers, /devices, /browsers, /operating-systems, /link/:hash, /real-time.
Create-link parameters
-_auto