CoreMVP
Reference

API Routes

Next.js Route Handler reference.

Overview

API routes are implemented as Next.js Route Handlers in src/app/api/. All routes call server-only services for business logic.

Base URL

  • Development: http://localhost:3000/api
  • Production: https://yourdomain.com/api

Authentication Routes

Billing Routes

User Routes

Utility Routes

Error Responses

All errors follow this format:

{
  "ok": false,
  "redirectPath": "/path?error=message&error_description=details"
}

Error information is encoded in the redirect path query parameters.

Adding New Routes

  1. Create a route file in src/app/api/:
src/app/api/example/route.ts
import { NextResponse } from 'next/server';

export async function GET() {
  return NextResponse.json({ hello: 'world' });
}

export async function POST(request: Request) {
  const body = await request.json();
  // Process request
  return NextResponse.json({ ok: true });
}
  1. For complex logic, create a service:
src/services/example/service.ts
import "server-only";

export async function processData(data: unknown) {
  // Business logic
  return { processed: true };
}
  1. Import and use the service in your route.

Was this page helpful?

On this page