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. |
password | string | No | Protect the link with a password (up to 200 chars). Visitors must enter it before being forwarded. |
expiresIn | string | No | Expiration preset: 1h, 24h, 7d or 30d. Omit for a link that never expires. |
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","expiresIn":"7d"}'
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,
"expiresAt": "2026-06-21T10:00:00.000Z",
"passwordProtected": false
}
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",
"expiresAt": null,
"passwordProtected": false,
"expired": false
}
For a password-protected link, originalUrl is returned as null so the destination stays hidden.
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" }.