The API we are working with in this Quarto document is an Open Movie Database, where you can search for specific movie/show titles. When prompted by a specific title, the API will return all the movies/shows that have that title or something similar.
library(httr)library(jsonlite)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ purrr::flatten() masks jsonlite::flatten()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Connecting the API Endpoint
omdb_endpoint <-"http://www.omdbapi.com/"
This is the base endpoint of the API, before any specifications are made for the movie/show we are looking for.
Searching the Data
search <-"?s=Batman"type <-"&type=movie"
This first R chunk is the most important and dynamic part of the search process. This is where you can specify the title of the film/show you are searching for. Additionally, you state whether you are looking for a movie or a show. In this case, I have filled in the fields to reflect that I am searching for a movie with the word “Batman” in the title.
*Alternatively, if you were looking for a show, you would simply type “series” instead of “movie” within the “type” specification.
This second R chunk is less dynamic in the information it specifies. Our API key will remain the same, and for the time being, we only want one page to be returned for each search, and we want the results to be in JSON format.
New, Specific URL
We will now combine all the specifications we made above into one conclusive URL: