URL Shortener API
A free, simple REST API to shorten URLs, set custom codes, generate QR codes, and read click stats. No API key required, and CORS is enabled so you can call it from anywhere.
Shorten a URL
POST /api/v1/shorten
Body (JSON):
| Field | Type | Required | Description |
|---|---|---|---|
url | string | Yes | The long http(s) URL to shorten. |
code | string | No | Custom back-half (4–30 letters, numbers, dashes). Random if omitted. |
Request
curl -X POST https://theurlshortner.com/api/v1/shorten \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/a/very/long/link","code":"my-link"}'
Response 201 Created
{
"code": "my-link",
"shortUrl": "https://theurlshortner.com/my-link",
"qrUrl": "https://theurlshortner.com/qr/my-link.svg",
"originalUrl": "https://example.com/a/very/long/link",
"clicks": 0
}
JavaScript (fetch)
const res = await fetch("https://theurlshortner.com/api/v1/shorten", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: "https://example.com" })
});
const data = await res.json();
console.log(data.shortUrl);
Get link stats
GET /api/v1/links/:code
Request
curl https://theurlshortner.com/api/v1/links/my-link
Response 200 OK
{
"code": "my-link",
"shortUrl": "https://theurlshortner.com/my-link",
"qrUrl": "https://theurlshortner.com/qr/my-link.svg",
"originalUrl": "https://example.com/a/very/long/link",
"clicks": 42,
"createdAt": "2026-06-14 10:00:00"
}
QR code
GET /qr/:code.svg
Returns a scannable SVG QR code for the short link. Use it in an <img> tag or download it for print.
<img src="https://theurlshortner.com/qr/my-link.svg" width="200" height="200" alt="QR code">
Errors
| Status | Meaning |
|---|---|
400 | Invalid URL, or invalid/reserved custom code. |
404 | Code not found (stats endpoint). |
409 | Custom code already taken. |
500 | Server error. |
Errors return JSON: { "error": "message" }.