next-api-layerNext API Layer
DocumentationAPI ReferenceExamples
next-api-layerNext API Layer

Production-grade API layer for Next.js with external JWT backends.

Documentation

  • Introduction
  • Installation
  • Quick Start
  • API Reference

Resources

  • Examples
  • Proxy
  • API Client
  • AuthProvider

Community

  • GitHub
  • Issues
  • Discussions
  • Contact

© 2026 Next API Layer. All rights reserved.

Created by
Documentation

Getting Started

  • Introduction
  • Installation
  • Quick Start

Core Concepts

  • How It Works
  • Token Management
  • Guest Tokens

Configuration

  • Auth Proxy
  • Proxy Handler
  • API Client
  • Security
  • i18n Integration

Client Side

  • AuthProvider
  • useAuth Hook

API Reference

  • API Reference
  • Types

Examples

  • Examples
  • Authentication Patterns
  • Role-Based Access
  • API Routes
  • Forms
  • Data Fetching
Changelog

Getting Started

  • Introduction
  • Installation
  • Quick Start

Core Concepts

  • How It Works
  • Token Management
  • Guest Tokens

Configuration

  • Auth Proxy
  • Proxy Handler
  • API Client
  • Security
  • i18n Integration

Client Side

  • AuthProvider
  • useAuth Hook

API Reference

  • API Reference
  • Types

Examples

  • Examples
  • Authentication Patterns
  • Role-Based Access
  • API Routes
  • Forms
  • Data Fetching
Changelog

i18n Integration

next-api-layer provides built-in support for internationalization (i18n), automatically detecting the user's locale and injecting it into API requests.

How It Works#

  1. Middleware extracts locale from URL path (e.g., /tr/blog → tr)
  2. Sets x-locale header on the request for downstream handlers
  3. API Client reads the header and appends ?lang={locale} to backend requests
Loading...

Configuration#

Auth Proxy (Middleware)#

TypeScript
Loading...

API Client#

TypeScript
Loading...

Configuration Options#

i18n (Proxy)#

| Option | Type | Default | Description | |--------|------|---------|-------------| | enabled | boolean | false | Enable i18n locale detection | | locales | string[] | [] | Valid locale codes to detect | | defaultLocale | string | - | Fallback locale when not detected |

i18n (API Client)#

| Option | Type | Default | Description | |--------|------|---------|-------------| | enabled | boolean | false | Enable i18n parameter injection | | paramName | string | 'lang' | Query parameter name | | locales | string[] | [] | Valid locale codes | | defaultLocale | string | - | Fallback locale |

With next-intl#

When using with next-intl, combine both middlewares using the afterAuth hook:

TypeScript
Loading...

Backend Implementation#

Your backend needs to filter content based on the lang query parameter:

Go (Fiber)#

Go
Loading...

Laravel#

PHP
Loading...

Django#

Python
Loading...

Database Schema#

Add a lang column to your content tables:

SQL
Loading...

Example: Full Setup#

1. Middleware (proxy.ts)#

TypeScript
Loading...

2. API Client (lib/api.ts)#

TypeScript
Loading...

3. Route Handler (app/api/posts/route.ts)#

TypeScript
Loading...

4. Page Component (app/[locale]/blog/page.tsx)#

TypeScript
Loading...

Supported Locales#

The library doesn't restrict which locales you can use. Common examples:

  • ISO 639-1: en, tr, ar, es, fr, de, ja, ko, zh
  • With region: en-US, en-GB, pt-BR, zh-CN, zh-TW

Just ensure your locales array in config matches your URL structure and backend expectations.