Example

Call the Places API from Node.js.

Keep the API key in your backend environment, call GET /v1/places with fetch, and handle error codes before using the results.

Node.js example.

const apiKey = process.env.OPEN_PLACES_API_KEY;

if (!apiKey) throw new Error("OPEN_PLACES_API_KEY is required");

const url = new URL("https://api.openplacesapi.com/v1/places");
url.search = new URLSearchParams({
  q: "coffee",
  lat: "40.7128",
  lon: "-74.0060",
  radius_mi: "25",
  limit: "10"
}).toString();

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${apiKey}`
  }
});

const body = await response.json();

if (!response.ok) {
  throw new Error(body?.error?.code || "places_api_error");
}

console.log(body.results);