nhl-api
A Rust client library for the NHL API. Get teams, scores, schedules, standings, and game stats.
Based on the excellent nhl-api-py.
Installation
Add to your Cargo.toml:
[]
= "0.5"
= { = "1", = ["full"] }
Quick Start
use ;
async
API Coverage
Standings
// Current standings
let standings = client.current_league_standings.await?;
// Standings for a specific date
let date = from_ymd_opt.unwrap;
let standings = client.league_standings_for_date.await?;
// Standings for a season (by season ID)
let standings = client.league_standings_for_season.await?;
// Season metadata (date ranges, etc.)
let seasons = client.season_standing_manifest.await?;
Schedule
// Today's schedule
let schedule = client.daily_schedule.await?;
// Schedule for a specific date
let date = from_ymd_opt.unwrap;
let schedule = client.daily_schedule.await?;
// Weekly schedule
let schedule = client.weekly_schedule.await?;
// Team-specific weekly schedule
let schedule = client.team_weekly_schedule.await?;
// Daily scores
let scores = client.daily_scores.await?;
Game Data
// Boxscore
let boxscore = client.boxscore.await?;
// Play-by-play
let pbp = client.play_by_play.await?;
// Game landing (lighter than play-by-play)
let landing = client.landing.await?;
// Game story narrative
let story = client.game_story.await?;
// Season series matchup
let series = client.season_series.await?;
// Shift chart data
let shifts = client.shift_chart.await?;
Players
// Player profile and stats
let player = client.player_landing.await?; // Connor McDavid
// Player game log
use GameType;
let log = client.player_game_log.await?;
// Search players
let results = client.search_player.await?;
Teams
// All teams (derived from standings)
let teams = client.teams.await?;
// Current roster
let roster = client.roster_current.await?;
// Historical roster
let roster = client.roster_season.await?;
// Club stats for a season
let stats = client.club_stats.await?;
// Available seasons for a team
let seasons = client.club_stats_season.await?;
// All franchises (including historical)
let franchises = client.franchises.await?;
Configuration
use ;
use Duration;
let config = ClientConfig ;
let client = with_config?;
Types
The library provides strongly-typed responses for all API endpoints. Key types include:
Standing- Team standings with points, wins, losses, etc.ScheduleGame- Scheduled game with teams and start timeBoxscore- Complete game boxscore with player statsPlayByPlay- All play events from a gamePlayerLanding- Player profile with career statsRoster- Team roster with player detailsGameType- Preseason, RegularSeason, Playoffs, AllStarGameState- FUT, PRE, LIVE, CRIT, FINAL, OFFGameDate- EitherNoworDate(NaiveDate)
Error Handling
All client methods return Result<T, NHLApiError>. Error variants include:
ResourceNotFound- 404 errorsRateLimitExceeded- 429 errorsBadRequest- 400 errorsServerError- 5xx errorsRequestError- Network/connection issuesJsonError- Deserialization failures
License
GPL-3.0-or-later