Skip to content

Files

Latest commit

 

History

History

w2d1bo-using-apis

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Aug 16, 2018
Aug 16, 2018
Oct 10, 2016
Oct 9, 2016

Using APIs

  • What is an API anyway?
  • Figuring out what you need
    • Authentication (keys, tokens etc.)
    • Endpoints
    • How to send/receive data
      • JSON
    • Example: Github API

The code discussed in class is inside /code.

NOTE: Some Github API endpoints may require an authentication token, which you can get here. You'll know when you hit one if you get an error message telling you how to do it. There are a few ways to make an HTTP request passing in the token, but the easiest one using request looks like this:

function requestWithToken(url, callback) {
  var requestData = {
    url: url,
    auth: {
      bearer: 'YOUR TOKEN HERE'
    },
    headers: {
      'User-Agent': 'request'
    }
  };

  request.get(requestData, callback); // The actual request. When the data is ready, `callback` is called.
}