Session Ready
Exercise

Extracting the response

Making requests is all well and good, but it's also not why you're here. What we really want to do is get the data the server sent back, which can be done with httr's content() function. You pass it an object returned from a GET (or POST, or DELETE, or...) call, and it spits out whatever the server actually sent in an R-compatible structure.

We're going to demonstrate that now, using a slightly more complicated URL than before - in fact, using a URL from the Wikimedia pageviews system you dealt with through the pageviews package, which is stored as url. Without looking too much at the structure for the time being (we'll get to that later) this request asks for the number of pageviews to the English-language Wikipedia's "Hadley Wickham" article on 1 and 2 January 2017.

Instructions
100 XP

httr is loaded in your workspace.

  • Make a GET request using the url object as the URL. Save the results as pageview_response.
  • Call content() on pageview_response to retrieve the data the server has sent back. Save the data as pageview_data.
  • Examine pageview_data with str().