@nhl-api/client
v3.1.4
Published
Async request wrapper around the [NHL API](https://statsapi.web.nhlApi.com/api/v1).
Downloads
17
Readme
@nhl-api/client
Async request wrapper around the NHL API.
Usage
import nhlApi from "@nhl-api/client";
nhlApi.getTeams({ name: "boston bruins" }).then(data => console.log(data));
nhlApi
.getPlayer({
name: "wayne gretzky",
stats: "statsSingleSeason",
season: "19841985"
})
.then(data => console.log(data));
API
- getTeams
- getPlayer
- getSchedule
- getGame
- getGameTypes
- getPlayTypes
- getPlayoffs
- getSeasons
- getStandings
- getStandingsTypes
- getDraft
- getProspects
- getAwards
- getVenues
- getDivisions
- getConferences
getTeams(options?)
Gets either a list of all teams, or individual team data.
By default, it returns a list of all NHL teams.
nhlApi.getTeams(); // returns an array of team objects
You can pass in either id
or name
as an option to get an individual team.
nhlApi.getTeams({ id: 20 }); // calgary flames
nhlApi.getTeams({ name: "boston" }); // boston bruins
nhlApi.getTeams({ name: "caps" }); // washington capitals
// if you search for a team by location, and that location has ever had more than 1 team, it will return an array of teams matching the query.
nhlApi.getTeams({ name: "toronto" }); // returns an array with the Maple Leafs, St. Pats, and Arenas.
Modifiers
Info.
Expand modifiers don't require the team.
prefix.
nhlApi.getTeams({ id: 6, expand: "roster" }); // returns the current team roster
nhlApi.getTeams({ id: 6, expand: "schedule.next" }); // returns the next game the team plays
nhlApi.getTeams({ id: 6, expand: "schedule.previous" }); // returns the last game a team played
nhlApi.getTeams({ id: 6, expand: "stats" }); // returns current season stats and rankings
getPlayer(options)
Gets data for a specific player. Requires at least 1 option param of either the player's name or ID.
nhlApi.getPlayer({ id: 8447400 });
nhlApi.getPlayer({ name: "wayne gretzky" });
// you can also search by nickname
nhlApi.getPlayer({ name: "the great one" });
// searching by just first or last name will probably result in multiple players.
// these will be returned in an array of player objects.
nhlApi.getPlayer({ name: "gretzky" }); // returns brett and wayne
// nickname searches must be exact
nhlApi.getPlayer({ name: "ace bailey" });
Modifiers
Info.
The only modifier this endpoint accepts is stats
:
nhlApi.getPlayer({
name: "wayne gretzky",
stats: "statsSingleSeason",
season: "19801981"
});
Accepted stat options:
statsSingleSeason
yearByYear
homeAndAway
winLoss
byMonth
byDayOfWeek
vsDivision
vsConference
vsTeam
gameLog
regularSeasonStatRanking
goalsByGameSituation
onPaceRegularSeason
Every stat option (except yearByYear
) also requires a season
param be passed. This is an 8 digit number with both years of a season- i.e. '20192020'.
getSchedule(options?)
Gets game scheduling information.
nhlApi.getSchedule(); // by default it returns all games for the current day
Modifiers
Info.
Modifiers don't require the schedule.
prefix.
nhlApi.getSchedule({ expand: "broadcasts" }); // shows game broadcasts
nhlApi.getSchedule({ expand: "boxscore" }); // boxscore for completed games
nhlApi.getSchedule({ expand: "linescore" }); // linescore for completed games
nhlApi.getSchedule({ id: 6 }); // gets today's games for a given team
nhlApi.getSchedule({ team: "bruins" }); // same as above
nhlApi.getSchedule({ date: "2019-10-27" }); // gets games for a given date
nhlApi.getSchedule({ startDate: "2019-09-30", endDate: "2019-10-14" }); // returns all games between a timeframe
// modifiers can be combined
nhlApi.getSchedule({
team: "bruins",
startDate: "2019-09-30",
endDate: "2019-10-14"
}); // returns all bruins games between 9/30/19 and 10/14/19
getGame(options)
Gets data from a specified game. Requires a game ID which can be retrieved from the getSchedule call, or you can decipher the game ID yourself.
nhlApi.getGame({ id: 2019020174 }); // by default it calls the /feed/live endpoint
Modifiers
Info.
// both of these return from the /feed/live endpoint
// same as default
// contains all details from a given game
nhlApi.getGame({ id: 2019020174, type: "feed" });
nhlApi.getGame({ id: 2019020174, type: "live" });
nhlApi.getGame({ id: 2019020174, type: "boxscore" }); // post-game details
nhlApi.getGame({ id: 2019020174, type: "linescore" }); // less-detailed post-game details
nhlApi.getGame({ id: 2019020174, type: "content" }); // returns media related to game
getGameTypes()
Info.
getPlayTypes()
getPlayoffs(options?)
Returns several playoff-specific details.
nhlApi.getPlayoffs(); // returns default playoff structure info
Info.
getSeasons(options?)
Info.
getStandings(options?)
Returns standings broken up by division
nhlApi.getStandings();
Modifiers
nhlApi.getStandings({ season: "19911992" }); // standings for specific season
nhlApi.getStandings({ date: "2019-09-30" }); // standings for a given day
nhlApi.getStandings({ expand: "record" }); // gives detailed individual team info
You can use the getStandingsType()
call to retrieve types to query standings by.
nhlApi.getStandings({ type: "wildCardWithLeaders", date: "2019-01-01" }); // returns complete wildcard standings for a given day
getStandingsTypes()
Returns standings types to use with getStandings()
.
nhlApi.getStandingsTypes(); // returns an array of all types
Info.
getDraft(options?)
Get round-by-round draft data for a given year
nhlApi.getDraft(); // returns current year by default
nhlApi.getDraft({ year: "1985" }); // returns draft for a given year
Info.
getProspects(options?)
nhlApi.getProspects(); // returns a full list of prospects
nhlApi.getProspect({ id: 53727 }); // returns an individual prospect
Note: the name
param cannot be used here, there's no database of all draft prospects to query.
getAwards(options?)
nhlApi.getAwards(); // returns all NHL awards
nhlApi.getAward({ id: 1 }); // returns individual award
getVenues(options?)
nhlApi.getVenues(); // returns all venues
nhlApi.getVenues({ id: 5064 }); // returns individual venue
getDivisions(options?)
nhlApi.getDivisions(); // returns all divisons
nhlApi.getDivisions({ id: 17 }); // returns individual division
getConferences(options?)
nhlApi.getConferences(); // returns all conferences
nhlApi.getConferences({ id: 5 }); // returns individual conferece
Props
All this made possible by Drew Hynes' NHL API Documentation.
Contributing
Please open an issue if you find anything incorrect / out-of-date / not working, etc.
built with skeletor 💀