Upgrade to Pro — share decks privately, control downloads, hide ads and more …

#ResBaz2019 Workshop - Accessing APIs using R

#ResBaz2019 Workshop - Accessing APIs using R

Open data on the internet is often made available, through Web service Application Programming Interfaces or APIs, by governments and other organisations. This workshop, will help you gain hands-on experience in requesting data from these different Web service APIs using R. Specifically, we will look into fetching weather and events data for Auckland region.

Manish Kukreja

July 12, 2019
Tweet

More Decks by Manish Kukreja

Other Decks in Education

Transcript

  1. BACKGROUND ON APIS • API stands for Application Programming Interface

    • GUI or CLI is for human-computer interaction • API is for program-program interaction • Some examples • Get data and plot it • Add a node to a computing cluster • Recognize faces as soon as an image is uploaded • APIs used on the web are mostly HTTP RESTful APIs or REST APIs
  2. HTTP VERBS • POST – used to create a record,

    data is passed using JSON or XML • GET – read single or list of records, response can be JSON or XML • PUT – update/replace single or entire list of records • PATCH – update/modify single or entire list of records • DELETE – delete the whole collection
  3. STEPS TO ACCESS API 1. Obtain the key for using

    the web service 2. Find the URL and endpoint path of the API 3. Convert input data to JSON format using toJSON() in the jsonlite package [optional] 4. Send input data to the API service using the appropriate HTTP VERB function in the httr package. Include API key in the function call. 5. Extract your results from the API response using the fromJSON() function
  4. 5. EXTRACT RESULTS FROM RESPONSE •Use httr::content() to extract data

    from response object •Transform it for easy manipulation •Visualize, merge or analyse it
  5. WORKSHOP CODE • Darksky weather forecast API notebook • https://datamak.ml/projects/data-analysis/Darksky-API

    • Microsoft sentiment analysis API notebook • https://datamak.ml/projects/data-analysis/Sentiment-API