This assignment illustrates the ability to get and process data from REST APIs, which usually use JSON format for the payload/body.
I’ve signed up on the dev NYT website and obtained an API key, which im storing in my parameter variables. Now I can make an HTTP GET request to access the data,
electionArticles <- fromJSON(paste0("https://api.nytimes.com/svc/search/v2/articlesearch.json?q=election&api-key=",params$key))
articlesdf <- as.data.frame(electionArticles)
class(articlesdf)## [1] "data.frame"
There appear to be nested dataframes as well, such as the headlines.
## [1] "Trump Advisers Talk of Palestinian Expulsions, but Activists Focus on Biden"
## [2] "Sherrod Brown Embarks on the Race of His Life"
## [3] "What to Watch in the South Carolina G.O.P. Primary"
## [4] "Nikki Haley Can’t Count on South Carolina’s Newcomers for Help"
## [5] "A Union Leader in Nebraska Tries to Leap to the Senate on Labor’s Strength"
## [6] "A Left-vs.-Left House Battle, Funded by a Split Over Israel"