1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Importing Data in R

Exercise

HTTP? httr! (2)

Web content does not limit itself to HTML pages and files stored on remote servers such as DataCamp's Amazon S3 instances. There are many other data formats out there. A very common one is JSON. This format is very often used by so-called Web APIs, interfaces to web servers with which you as a client can communicate to get or store information in more complicated ways.

You'll learn about Web APIs and JSON in the video and exercises that follow, but some experimentation never hurts, does it?

Instructions

100 XP
  • Use GET() to get the url that has already been specified in the sample code. Store the response as resp.
  • Print resp. What is the content-type?
  • Use content() to get the content of resp. Set the as argument to "text". Simply print out the result. What do you see?
  • Use content() to get the content of resp, but this time do not specify a second argument. R figures out automatically that you're dealing with a JSON, and converts the JSON to a named R list.