Fetch stations on the server
For a Next.js website, create app/api/radio-stations/route.ts. This example forwards station metadata and useful quota headers, while keeping the bearer key on the server.
TypeScript
export async function GET() {
const key = process.env.NAIJA_RADIO_API_KEY;
const base = process.env.NAIJA_RADIO_API_BASE_URL;
if (!key || !base) {
return Response.json(
{ error: "Radio integration is not configured" },
{ status: 503 },
);
}
try {Continue reading · 35 more lines
const response = await fetch(
`${base.replace(/\/$/, "")}/stations?countryCode=NG&limit=100`,
{
headers: { Authorization: `Bearer ${key}` },
cache: "no-store",
redirect: "error",
signal: AbortSignal.timeout(12000),
},
);
const headers = new Headers({
"Content-Type": "application/json",
"Cache-Control": "private, no-store",
});
for (const name of [
"Retry-After",
"X-RateLimit-Limit",
"X-RateLimit-Remaining",
"X-RateLimit-Reset",
]) {
const value = response.headers.get(name);
if (value) headers.set(name, value);
}
return new Response(await response.text(), {
status: response.status,
headers,
});
} catch {
return Response.json(
{ error: "Radio service is temporarily unavailable" },
{ status: 503 },
);
}
}Before launch, protect this consumer endpoint using the website’s authentication or rate limiting. All visitors share the partner key’s quota. Higher-traffic sites should cache station metadata on their backend within the appropriate access boundary.