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?
Este ejercicio forma parte del curso
Intermediate Importing Data in R
Instrucciones del ejercicio
- Use
GET()
to get theurl
that has already been specified in the sample code. Store the response asresp
. - Print
resp
. What is the content-type? - Use
content()
to get the content ofresp
. Set theas
argument to"text"
. Simply print out the result. What do you see? - Use
content()
to get the content ofresp
, 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.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# httr is already loaded
# Get the url
url <- "http://www.omdbapi.com/?apikey=72bc447a&t=Annie+Hall&y=&plot=short&r=json"
# Print resp
# Print content of resp as text
# Print content of resp