Skip to content

Latest commit

 

History

History
45 lines (31 loc) · 1.21 KB

USAGE.md

File metadata and controls

45 lines (31 loc) · 1.21 KB

Usage

Method Design

  • Each API method will take 2 optional parameters:

    • query

      • Query parameters for the given request. Refer to this for the list of methods and their accepted parameters. Some methods may require this parameter (the APIs will throw a 400 error if a required parameter is missing).
    • cb

      • Optional error-first callback for your request.
  • Whether or not a callback is provided, the request will return a standard Promise, use whichever you prefer.

    const nba = require('nba').default;
    
    nba.stats.allPlayers().then(res => {
      console.log(res)
    });
    
    // this also works
    nba.stats.allPlayers(function(err, res) {
      if (err) {
        console.error(err);
        return;
      }
    
      console.log(res);
    });
    
    // not sure why you'd do this, but it also works
    nba.stats.allPlayers((err, res) => {
      console.log(res)
    }).then(res => {
      console.log(res)
    });

Method Parameters

  • Each method will take a more-or-less unique set of query parameters.
  • The list of methods and accepted query parameters for each API can be found in DATA.md and STATS.md.