Next.js / Backend APIs
Step 16 of 23
Forward locale to backend APIs
When a Next.js frontend calls a separate backend, send the active Altified locale with the request so backend SDKs can return translated data.
Use altifiedFetch in your shared API client. It forwards the current locale with Accept-Language, so a Django backend using django_altified receives the same language as the current Next route.
api/client.js
import { altifiedFetch } from "@altified/next/fetch";
const response = await altifiedFetch(BACKEND_URL + path, {
credentials: "include",
});If your app uses Axios, attach the Altified interceptor to the shared Axios instance instead.
api.js
import axios from "axios";
import { altifiedAxiosInterceptor } from "@altified/next/axios";
const api = axios.create({
baseURL: BACKEND_URL,
withCredentials: true,
});
altifiedAxiosInterceptor(api);Use one shared client
You should not edit every request. Add the helper once to the central fetch wrapper or Axios instance that your app already uses for backend calls.