NanoLink API

Shorten links. Track every click. Self-destruct when done.


Endpoints

Authentication

Stats and link management routes require a Bearer token. Pass it in your request headers — that's it.

Authorization: Bearer hackclub-pi-zero
POST /api/shorten 30 REQ / MIN

Turns a URL into a short code. You can bring your own slug (vanity URLs), cap how many times the link can be visited before it deletes itself, or set a hard expiry date. Payloads are validated with Zod.

cURL
201 Created
{
  "success": true,
  "message": "Link shortened successfully!",
  "code": "hack",
  "shortUrl": "http://localhost:3000/hack",
  "originalUrl": "https://hackclub.com"
}

Optional body fields

  • customCode: Pick your own slug instead of a random hash.
  • maxClicks: Link deletes itself after X visits.
  • expiresAt: ISO-8601 timestamp. Link is gone after this moment.
GET /:code

Redirects to the destination. On every hit, it silently parses the User-Agent to record OS, device, and browser — then fires a Discord webhook in the background. If the link has hit its click limit, it returns 410 and deletes itself.

cURL
301 Moved Permanently
HTTP/1.1 301 Moved Permanently
Location: https://hackclub.com
410 Gone — click limit reached
HTTP/1.1 410 Gone
"This link has reached its maximum view count and self-destructed."
GET /api/qr/:code

Returns a high-res PNG QR code for any short link. Generated in-memory and streamed directly.

cURL
200 OK
HTTP/1.1 200 OK
Content-Type: image/png

[Binary image data]
GET /api/stats/:code AUTH REQUIRED

Click analytics for a single link. Joins the link row with its click events — each one tagged with OS, device, and browser. Useful for understanding who's actually hitting your links.

cURL
200 OK
{
  "success": true,
  "data": {
    "id": "hack",
    "originalUrl": "https://hackclub.com",
    "clicks": 1,
    "createdAt": "2026-05-09T10:11:35.433Z",
    "lastClicked": "2026-05-09T10:22:17.541Z",
    "recentActivity": [
      {
        "id": 1,
        "os": "Mac OS",
        "browser": "Chrome",
        "device": "Desktop",
        "timestamp": "2026-05-09T10:22:17.541Z"
      }
    ]
  }
}
GET /api/links AUTH REQUIRED

Lists all active short codes in the database. Paginated via ?page=1&limit=10 query params so it won't fall over on large datasets.

cURL
200 OK
{
  "success": true,
  "meta": {
    "totalItems": 15,
    "totalPages": 2,
    "currentPage": 1,
    "itemsPerPage": 10
  },
  "data": [
    {
      "id": "hack",
      "originalUrl": "https://hackclub.com",
      "clicks": 42,
      "createdAt": "2026-05-08T09:00:00Z",
      "expiresAt": "2026-06-08T09:00:00Z"
    }
  ]
}