STAT-API
MLB Cookbook

Auto-paginate every MLB team

Every table exposes an auto-paging iterator that follows the next_from_id keyset cursor until it runs out — so you can consume a whole table without writing the paging loop.

1.Walk every page of teams

The iterator issues one request per page, following the cursor, and yields each row. Collect them all into a list.

const teams: MLBTeam[] = []
for await (const row of api.mlb.teams.iter()) teams.push(row)

The complete program

Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.

import { StatApi, type MLBTeam } from '@stat-api/client'

const api = new StatApi() // reads STAT_API_KEY from the environment

// Walk every page of teams
const teams: MLBTeam[] = []
for await (const row of api.mlb.teams.iter()) teams.push(row)

// Report how many rows the iterator collected
console.log(`fetched ${teams.length} teams`)