I created an API Key for the books from NYTimes. I will be looking for books in the health category. I use PostMan to see how the output of the call to the web API will look like in a beautiful JSON format. This is what most developers out there use.
library(httr)
library(dplyr)
library(stringi)
library(stringr)
library(jsonlite)
library(kableExtra)
booksApiKey <- "M69aWzqQECFYN9tTHAG0Gne8dzQK19KR"
Url <- paste0("https://api.nytimes.com/svc/books/v3/lists/health.json?api-key=", booksApiKey)
health_books <- readLines(Url, warn = FALSE)
#Read JSON data
health_books <- fromJSON(health_books)
health_books_df <- health_books$results$books
#display columns names
colnames(health_books_df)
## [1] "rank" "rank_last_week" "weeks_on_list"
## [4] "asterisk" "dagger" "primary_isbn10"
## [7] "primary_isbn13" "publisher" "description"
## [10] "price" "title" "author"
## [13] "contributor" "contributor_note" "book_image"
## [16] "book_image_width" "book_image_height" "amazon_product_url"
## [19] "age_group" "book_review_link" "first_chapter_link"
## [22] "sunday_review_link" "article_chapter_link" "isbns"
## [25] "buy_links" "book_uri"
#considering few columns to load
health_books_df = health_books_df[c("title","author","publisher","primary_isbn10")]
#show the output
#health_books_df
kable(health_books_df) %>%
kable_styling(bootstrap_options = c("striped", "hover"))
title | author | publisher | primary_isbn10 |
---|---|---|---|
WHEN BREATH BECOMES AIR | Paul Kalanithi | Random House | 081298840X |
THE SUBTLE ART OF NOT GIVING A F*CK | Mark Manson | HarperOne/HarperCollins | 0062457713 |
THE WHOLE30 COOKBOOK | Melissa Hartwig | Houghton Mifflin Harcourt | 0544854411 |
THE LOSE YOUR BELLY DIET | Travis Stork | Ghost Mountain | 1939457599 |
THE GENE | Siddhartha Mukherjee | Scribner | 1476733503 |
MEDICAL MEDIUM LIFE-CHANGING FOODS | Anthony William | Hay House | 1401948324 |
GREEN SMOOTHIES FOR LIFE | J J Smith | Atria | 1501100653 |
THE ZERO SUGAR DIET | David Zinczenko with Stephen Perrine | Ballantine | 0345547985 |
10-DAY GREEN SMOOTHIE CLEANSE | J J Smith | Atria | 1501100106 |
BEING MORTAL | Atul Gawande | Metropolitan/Holt | 0805095152 |