Build your URL Shortener API with AI in under 5 minutes

Build a Bitly-style URL shortener with a JSON POST /shorten endpoint, custom aliases, optional expiry dates, click counters, and a redirect handler — generated from a single prompt.

Cara kerjanya

Langkah 1

Deskripsikan ide Anda

Tulis prompt teks biasa yang mendeskripsikan apa yang Anda inginkan.

Langkah 2

AI membangunnya

FloopFloop menghasilkan kode siap produksi secara instan.

Langkah 3

Deploy & aktifkan

Proyek Anda di-hosting pada subdomainnya sendiri dalam hitungan menit.

Mengapa membangun dengan AI daripada menyewa developer?

FloopFloopDeveloper tradisional
Waktu peluncuranKurang dari 5 menit2-8 minggu
BiayaMulai dari $0$5.000 - $50.000+
PemeliharaanSudah termasukRetainer berkelanjutan

Coba prompt ini

Salin prompt apa pun di bawah ini dan tempelkan ke FloopFloop untuk memulai.

Build a URL shortener REST API. POST /api/shorten accepts {url, alias?, expires_at?, tags?} and returns the short_url. The catch-all /[alias] route 302s to the destination, bumps a click counter, and 404s on missing or expired entries. Auto-generated aliases are 6 lowercase alphanumeric chars (cryptographically random — no Math.random). All non-http(s) protocols rejected at write + read time.

Create a branded link shortener for a marketing team. Custom alias format /[campaign]-[id], a JSON GET /api/links endpoint that lists every link with click counts grouped by campaign tag, and a 100-requests-per-IP-per-hour rate limit on the shorten endpoint to block bulk-spammer scripts.

Design an internal link shortener for a small company. POST /api/shorten requires an X-API-Key header that matches an env var; the catch-all redirect route is open so anyone with the short URL can use it. Storage is in-memory (per Lambda container) — fine for the company's modest traffic and resets on every deploy.

Build a temporary-link service. Every shortened URL gets a mandatory expires_at — max 7 days from creation. The /[alias] route returns 410 Gone with a friendly 'link expired' JSON for expired entries instead of redirecting. A daily cron sweeps rows with expires_at < now() to keep the table bounded.

Pertanyaan yang sering diajukan

Where do shortened links live?
The default template uses an in-memory Map for storage so the API is 200-able out of the box without a DB schema migration. Replace with the project's Postgres (`import sql from '@/lib/db'`) when graduating to a multi-replica deploy — the docblock at the top of /api/shorten/route.ts walks through the swap.
How does the catch-all redirect route avoid colliding with /api/*?
Next.js's resolver matches static segments first, so /api/health, /api/shorten, /favicon.ico, and /_next/* all win over /[alias] without any extra config. The redirect handler also rejects alias values that don't match the {3..30}-char regex, so /favicon.png lookups 404 cleanly instead of hitting the DB.
What stops someone from creating a `javascript:alert(1)` redirect?
Every destination URL is run through a safeUrl() check at write time AND again at read time on the redirect handler. The function rejects every non-http(s) scheme — javascript:, data:, file:, view-source:, etc. — so the shortener can't be used as a XSS-as-a-service for phishing pages.
Is there a rate limit on the shorten endpoint?
Yes — 100 shorten requests per IP per hour, salt-hashed against FLOOP_PROJECT_ID. Check fires BEFORE body parse so a hostile client can't waste validation time after they've hit the cap. The redirect handler itself is open (it's just a redirect, not a write).
Can I use custom aliases like /sale-2026?
Yes. POST /api/shorten accepts an optional `alias` field; the validator rejects reserved slugs (api, health, admin, login, signup) and anything outside the {3..30}-char allowlist regex. If the alias is taken the API returns 409 Conflict.
Can I add link expiration?
Yes — the API accepts an optional `expires_at` ISO timestamp. The redirect route returns 410 Gone past that timestamp instead of 302'ing. There's no built-in DB sweep of expired rows; if your project keeps the in-memory store, expiry happens organically on cold starts.
What about analytics on clicks?
The default template bumps a per-link `clicks` counter on every redirect (fire-and-forget so it never delays the 302). For richer analytics — per-day timeseries, geo, referrer breakdown — refine into the chat asking for a `click_events` table and a /api/links/[id]/stats endpoint.

Builder terkait

Jelajahi kategori lainnya

Siap untuk membangun?

Mulai bangun proyek Anda sekarang — tanpa perlu coding.

Mulai Membangun