Next.js implementation guide

    How to add a link shortener API to a Next.js app

    Use 1get from a Next.js application to create branded short links, return QR metadata in the same response, and keep retries safe with idempotency.

    7 min
    Updated 2026-04-07
    Next.js + link API
    Next.js App Router
    Bearer API key
    One-call link + QR
    Idempotency-safe
    Quick briefing
    SSR guide page
    Primary route

    POST /api/v1/links/shorten

    Auth model

    Authorization: Bearer <api_key>

    Best plan lane

    Basic for first production use, Business for heavier volume

    Best fit

    App backends, invite flows, transactional messaging, customer-share surfaces

    If your Next.js product needs short links, QR assets, or programmatic redirect control, treat it as link infrastructure rather than a dashboard shortcut. That means server-side auth, stable request contracts, and a clear plan for retries, usage, and ownership.

    1get is built for that model. Human admins use the dashboard to create scoped keys. Your app uses the external API to create links, retrieve metadata, and keep automation activity tied to the subscribed organization.

    Architecture

    Use a link API instead of a private slug table

    A custom slug table looks simple until you need QR support, auditing, rate controls, and machine access patterns that work across products, jobs, and internal tools.

    • The same API surface can support app backends, queue workers, and AI flows.
    • Short URL creation and QR metadata come back in the same response.
    • Usage limits and key scopes stay outside your application business logic.
    Practical rule

    Keep shortening on the server side. Do not hand public browser clients raw API keys or tenant authority.

    Implementation

    Create one server-side helper around the shorten endpoint

    A small helper in your Next.js server layer is enough for the first integration. It can inject the API key, create an idempotency key for retries, and return a stable contract to the rest of your app.

    Keep the helper inside a route handler, server action, or application service. That way the API key stays in server-side environment variables and the rest of the app consumes a simple function.

    • Use an Idempotency-Key when the caller might retry.
    • Store the returned link id if your app will read link or QR metadata later.
    • Let the rest of the product work with short_url and qr_code.url instead of the raw external response.
    Validation cURL

    Use a direct cURL request first when you want to verify auth, idempotency, and the QR response before wiring the app helper.

    bash
    curl -X POST https://1get.site/api/v1/links/shorten \
      -H "Authorization: Bearer 1g_live_xxxxx" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: 7c8ff59c-17aa-4178-8890-b71af19f5261" \
      -d '{
        "original_url": "https://acme.ai/workflows/agent-invite/42",
        "custom_slug": "agent-launch",
        "qr": { "include": true, "format": "SVG", "size": 256 }
      }'
    Next.js server helper

    A small server-only helper is enough for the first production lane.

    ts
    import 'server-only';
    
    type ShortenPayload = {
      original_url: string;
      custom_slug?: string;
      qr?: { include?: boolean; format?: 'PNG' | 'SVG'; size?: number };
    };
    
    export async function createShortLink(payload: ShortenPayload) {
      const response = await fetch('https://1get.site/api/v1/links/shorten', {
        method: 'POST',
        headers: {
          Authorization: `Bearer ${process.env.ONEGET_API_KEY}`,
          'Content-Type': 'application/json',
          'Idempotency-Key': crypto.randomUUID(),
        },
        body: JSON.stringify(payload),
        cache: 'no-store',
      });
    
      if (!response.ok) {
        throw new Error(`1get shorten failed: ${response.status}`);
      }
    
      const body = await response.json();
      return body.data;
    }
    Delivery

    Render the returned contract and keep the integration operationally clean

    The MVP route is designed so a single response is enough for most product surfaces: the short URL is ready for the UI and the QR object can feed a download button, share flow, or customer-facing asset.

    As volume grows, pair the shorten helper with GET /api/v1/usage so your app or admin tooling can see the current billing window, active key count, and usage limit before traffic surprises the team.

    • Basic is usually enough for the first production flow.
    • Business is the more natural plan once multiple environments, teams, or read-heavy integrations appear.
    • Do not build tenant selection into your client payloads. Organization context comes from the API key.
    Related guides

    Keep the intent cluster connected.

    These follow-up guides cover adjacent implementation paths so searchers and evaluators can move deeper without losing context.