Node.js
A small client with retries and paging, the lists, live scores, one game's live updates, types for TypeScript, and the server that keeps your key away from your apps and pages.
You need: Node.js 18 or later; nothing to install for the client.
Keep the key out of the code
Put it in the environment, or in your host's secret store (Vercel, Render, Fly, AWS, Azure and Google Cloud all have one).
# .env (never committed: add it to .gitignore) GAELICSCORE_KEY=gs_live_... # Node.js 20.6 or later reads it for you: node --env-file=.env fixtures.mjsA small client
One function for a request, which waits and tries again on the minute's limit, and one that walks every page of a list.
// gaelicscore.mjs: a small client for the GaelicScore.ie Data API. Node.js 18 or later (fetch is built in). const BASE = "https://gaelicscore.ie/api"; const KEY = process.env.GAELICSCORE_KEY; if (!KEY) throw new Error("Set GAELICSCORE_KEY to your key"); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); export class ApiError extends Error { constructor(status, code, message, requestId) { super(`${code}: ${message}`); Object.assign(this, { status, code, requestId }); } } /** One request. Waits and tries again on the minute's limit and on errors on our side. */ export async function api(path, params = {}) { const url = new URL(BASE + path); for (const [name, value] of Object.entries(params)) { if (value !== undefined && value !== null) url.searchParams.set(name, String(value)); } for (let attempt = 0; ; attempt++) { const res = await fetch(url, { headers: { Authorization: `Bearer ${KEY}`, Accept: "application/json" } }); if (res.ok) return res.json(); const body = await res.json().catch(() => ({})); const code = body.error?.code ?? `http_${res.status}`; // The minute's limit and our errors pass; a month's quota, a bad key or a bad request do not. const again = (code === "rate_limited" || res.status >= 500) && attempt < 3; if (!again) throw new ApiError(res.status, code, body.error?.message ?? res.statusText, res.headers.get("x-request-id")); await sleep((Number(res.headers.get("retry-after")) || 2 ** attempt) * 1000); } } /** Every item of a list, page after page. */ export async function* every(path, params = {}) { let cursor; do { const page = await api(path, { limit: 100, ...params, cursor }); yield* page.data; cursor = page.meta.next; } while (cursor); }Fixtures and results
The next games of a county, and every result of the season page by page.
// fixtures.mjs import { api, every } from "./gaelicscore.mjs"; // The next 20 games in Kerry, soonest first. Times are Irish time; null is "not confirmed". const { data: fixtures } = await api("/v1/fixtures", { county: "kerry", limit: 20 }); for (const g of fixtures) { const time = g.throwIn ? g.throwIn.slice(11, 16) : "TBC"; console.log(`${g.date} ${time} ${g.home.name} v ${g.away.name} (${g.competition.name})`); } // Every hurling result in Kerry this season, page after page. for await (const g of every("/v1/results", { county: "kerry", code: "hurling" })) { console.log(`${g.date} ${g.home.name} ${g.score.home.text} ${g.away.name} ${g.score.away.text}`); }Games in play
Ask every 30 seconds while games are on; print a score only when it changes.
// live.mjs: the games in play in Kerry, every 30 seconds, printing each score as it changes. import { api } from "./gaelicscore.mjs"; const last = new Map(); async function poll() { const { data, meta } = await api("/v1/live", { county: "kerry" }); for (const g of data) { const home = g.live.home?.text ?? "-"; const away = g.live.away?.text ?? "-"; if (last.get(g.id) === home + away) continue; last.set(g.id, home + away); const whose = g.live.official ? "official" : "reported"; console.log(`${g.home.name} ${home} ${g.away.name} ${away} (${whose}, ${meta.delayedMinutes} min late)`); } } await poll(); setInterval(() => poll().catch((error) => console.error(error.message)), 30_000);Follow one game (Business and Enterprise)
Each score a source gave, oldest first, asking only for what is newer than the last you hold.
// follow.mjs: one game's live updates, asking only for what is new (Business and Enterprise). import { api } from "./gaelicscore.mjs"; const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); export async function follow(matchId, onUpdate) { let since; for (;;) { const { data, meta } = await api(`/v1/matches/${matchId}/updates`, { since }); for (const update of data) { onUpdate(update); // { at, kind, minute, home, away, source } since = update.at; } if (meta.phase === "result" || meta.phase === "off") return; await sleep(15_000); } } await follow(process.argv[2], (u) => console.log(u.at, u.kind, u.home.text, u.away.text, u.source));Types for TypeScript
Generate them from the OpenAPI document.
# Types for TypeScript from the OpenAPI document (npm install -D openapi-typescript). curl -s -H "Authorization: Bearer $GAELICSCORE_KEY" \ https://gaelicscore.ie/api/v1/openapi.json -o gaelicscore.openapi.json npx openapi-typescript gaelicscore.openapi.json -o gaelicscore.d.tsA server for your app or website
Your iOS and Android apps and your web pages call this, never the API: the key stays on the server. It serves only the paths you allow, and holds each answer for 15 seconds, so a thousand users watching one game make one request.
// server.mjs: your own server, between your app or website and GaelicScore.ie. The key stays here: the app never // has it. Node.js 18+ and Express (npm install express). Put your own sign-in, or Apple's App Attest and Google's // Play Integrity, in front of it, so only your app is answered. import express from "express"; const KEY = process.env.GAELICSCORE_KEY; const ALLOWED = /^\/v1\/(live|fixtures|results|counties|competitions|clubs|matches\/[0-9a-f-]{36}(\/updates)?)$/; const HOLD_MS = 15_000; // one answer serves all your users for 15 seconds: fewer requests, the same scores const held = new Map(); const app = express(); app.get(/^\/gaa(\/v1\/.*)$/, async (req, res) => { const path = req.params[0]; if (!ALLOWED.test(path)) return res.status(404).json({ error: { code: "not_found", message: "Not served here" } }); const url = new URL("https://gaelicscore.ie/api" + path); for (const [name, value] of Object.entries(req.query)) if (typeof value === "string") url.searchParams.set(name, value); const copy = held.get(url.href); if (copy && Date.now() - copy.at < HOLD_MS) return res.status(200).type("application/json").send(copy.body); try { const upstream = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } }); const body = await upstream.text(); if (upstream.ok) { if (held.size > 1_000) held.clear(); held.set(url.href, { at: Date.now(), body }); } res.status(upstream.status).type("application/json").send(body); } catch { res.status(502).json({ error: { code: "unavailable", message: "GaelicScore.ie did not answer; try again" } }); } }); app.listen(3000, () => console.log("http://localhost:3000/gaa/v1/live"));