Build a city events page
A page that lists what's on in one city this month, rendered on your server. It uses two APIs: City Suggestions to find the exact city, and List Events by City (Advanced) to list its events.
You need an API key and Node.js 18 or later. The code runs only on your server: the key never reaches the browser.
1. Set up the key
Keep the key in environment variables, never in code:
export AE_API_KEY="ae_api_your_key"export AE_BASE_URL="https://developer.allevents.in/v1"Every call goes through one small helper. It sends the key in the X-API-Key header, sets a timeout, and turns a 429 into an error that says how long to wait.
// allevents.js (server-side only)const BASE = process.env.AE_BASE_URL;const KEY = process.env.AE_API_KEY;export async function aeGet(path, params) { const response = await fetch(`${BASE}${path}?${new URLSearchParams(params)}`, { headers: { "X-API-Key": KEY }, signal: AbortSignal.timeout(45_000), }); if (response.status === 429) { const wait = Number(response.headers.get("retry-after") ?? 60); throw new Error(`Rate limited: retry in ${wait} s`); } return { status: response.status, body: await response.json() };}2. Find the exact city
City names are ambiguous: there is more than one Austin. Look the city up once and keep the city, state and country it returns.
curl "$AE_BASE_URL/geo/city_suggestion?city=Austin" \ -H "X-API-Key: $AE_API_KEY"Store the result with your page (for example { city: "Austin", state: "TX", country: "United States" }) so you don't look it up on every visit.
3. List the city's events
Ask for this month's events, soonest first, one page at a time. page starts at 0.
// events.js (continued)export async function cityEvents(place, page = 0) { const { status, body } = await aeGet("/events/list_es", { ...place, when: "this_month", sort: "date", reqRows: "10", page: String(page), }); // Always check `error` as well as the status: 200 with error > 0 means "nothing usable". if (status !== 200 || body.error > 0) return []; return body.data;}- At most 10 events come back per call (
reqRowsup to 10). A page can be shorter thanreqRowseven when more events exist (for example with limited coverage). Offer a "More events" link until a page comes back empty. - Repeating the same call within an hour is answered from the cache and costs 0 credits (
credits_used: 0), so don't addcached=falseto a page like this.
4. Render the page
display.short is ready-made date and time text in the venue's time: show it as is. (start_at is the same moment in ISO 8601 with the venue's offset, and start_ts in Unix seconds, if you format or sort yourself; see Dates and times.) Text fields are plain text, so escape every one before you put it in HTML.
// server.jsimport { createServer } from "node:http";import { cityEvents } from "./events.js";const AUSTIN = { city: "Austin", state: "TX", country: "United States" };const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);createServer(async (req, res) => { const page = Number(new URL(req.url, "http://localhost").searchParams.get("page") ?? 0); const events = await cityEvents(AUSTIN, page); const items = events .map((e) => `<li><a href="${esc(e.event_url)}">${esc(e.eventname)}</a> · ${esc(e.display.short)} · ${esc(e.venue.name)}</li>`) .join(""); res.writeHead(200, { "content-type": "text/html; charset=utf-8" }); res.end(`<h1>Events in Austin this month</h1><ul>${items || "<li>No events found.</li>"}</ul>${events.length ? `<a href="?page=${page + 1}">More events</a>` : ""}<p>Data from <a href="https://allevents.in">AllEvents</a></p>`);}).listen(3000);Where you show the data publicly, keep the "Data from AllEvents" line with its link (see the API Terms of Use in the developer portal).
Next steps
- Add filters such as
category=musicorprice=free: see How filters combine. - Link each event to
event_url, its AllEvents page with tickets and details. - Handle the error codes you can get, such as
credits_exhausted.