STAT-API

Build the MLB standings

season_team_stats has one row per team per season — wins, losses, games played. Resolve the current season, page the whole table, and sort by wins to build the standings.

  1. 1. Resolve the current season

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/mlb/seasons?limit=200'
  2. 2. Page every team's season record

    season_team_stats is keyed by season_id — one row per team; the auto-pager collects them all.

    curl -sS --compressed \
      -H 'Authorization: Bearer YOUR_API_KEY' \
      'https://api.stat-api.com/api/v1/mlb/season_team_stats?season_id=2026'
  3. 3. Order by wins, best first

    Sort the accumulated rows by wins descending.

    const standings = [...rows].sort((a, b) => b.wins - a.wins)
  4. 4. Take the top ten

    const top = standings.slice(0, 10)
  5. 5. Print the standings

    console.log("MLB standings — top 10 by wins")
    console.log(["team_id", "wins", "losses"].join('\t'))
    for (const row of top) {
      console.log([String(row.team_id ?? ''), String(row.wins ?? ''), String(row.losses ?? '')].join('\t'))
    }