Docs · Next.js

Frameworks

Next.js

Keep the key on the server: proxy search, geocoding and routing through a Route Handler.

Example

app/api/places/route.tsts
1// app/api/places/route.ts — search from the server, so the key2// stays secret (ORVIA_API_KEY in .env). The map itself works like3// the React example inside a "use client" component.4export async function GET(request: Request) {5  const q = new URL(request.url).searchParams.get("q") ?? "";67  const res = await fetch(8    `https://orviamaps.ir/api/v1/search?q=${encodeURIComponent(q)}&limit=5`,9    { headers: { Authorization: `Bearer ${process.env.ORVIA_API_KEY}` } }10  );1112  return Response.json(await res.json(), { status: res.status });13}

Replace YOUR_API_KEY with a key from your account, or read it from an environment variable as shown.