Session Ready
Exercise

Wrapup: returning nice API output

How might all this work together? A useful API function will retrieve results from an API and return them in a useful form. In Chapter 2, you finished up by writing a function that retrieves data from an API that relied on content() to convert it to a useful form. To write a more robust API function you shouldn't rely on content() but instead parse the data yourself.

To finish up this chapter you'll do exactly that: write get_revision_history() which retrieves the XML data for the revision history of page on Wikipedia, parses it, and returns it in a nice data frame.

So that you can focus on the parts of the function that parse the return object, you'll see your function calls rev_history() to get the response from the API. You can assume this function returns the raw response and follows the best practices you learnt in Chapter 2, like using a user agent, and checking the response status.

Instructions
100 XP

Fill in the ___ to finish the function definition.

  • Use read_xml() to turn the content() of rev_resp as text into an XML object.
  • Use xml_find_all() to find all the rev nodes in the XML.
  • Parse out the "user" attribute from rev_nodes.
  • Parse out the content from rev_nodes using xml_text().
  • Finally, call get_revision_history() with article_title = "Hadley Wickham".