These server-side examples use standard HTTP clients. Configure ATM_API_BASE_URL and ATM_API_KEY as shown in the quickstart. No API-specific SDK is required.
JavaScript: find a movie and read its ending
Run this as a Node.js script with built-in fetch support. It checks HTTP failures, handles an empty search, and verifies content availability before requesting the explanation.
Code
const baseUrl = process.env.ATM_API_BASE_URL;const apiKey = process.env.ATM_API_KEY;if (!baseUrl || !apiKey) { throw new Error("Set ATM_API_BASE_URL and ATM_API_KEY.");}async function get(path, params = {}) { const url = new URL(`${baseUrl.replace(/\/$/, "")}${path}`); url.search = new URLSearchParams(params).toString(); const response = await fetch(url, { headers: { Authorization: `Bearer ${apiKey}` }, signal: AbortSignal.timeout(15000), }); const body = await response.json(); if (!response.ok) { const error = new Error(body.error?.message ?? `HTTP ${response.status}`); error.status = response.status; error.code = body.error?.code; error.requestId = body.error?.request_id; error.retryAfter = response.headers.get("Retry-After"); throw error; } return body;}const results = await get("/movies", { imdb_id: "tt1375666", limit: "1" });const match = results.data[0];if (!match) { console.log("No matching movie in the catalog.");} else { const { data: movie } = await get(`/movies/${match.id}`); if (movie.available_content.includes("ending")) { const { data: ending } = await get(`/movies/${movie.id}/content/ending`); console.log(ending.text); } else { console.log("No ending explanation is available for this movie."); }}
Availability can change between calls, so handle content_not_available in your application's error boundary too. These examples make a single attempt per request; add bounded retries according to Errors and limits.
For an interactive list, request the next page when the reader asks for more. Keep the filters alongside the cursor so subsequent requests use the same search.