base_url <- "https://www.wsdot.wa.gov"
endpoint <- "ferries/api/vessels/rest/vesselverbose"
# Compose the API request
req <- request(base_url) |>
req_url_path_append(endpoint) |>
req_url_query(apiaccesscode = Sys.getenv("WSDOT_ACCESS_CODE"))
# perform the request
response <- req |>
req_perform()
# convert the body of the response to a tibble
response_body <- response |>
resp_body_string() |>
jsonlite::fromJSON() |>
as_tibble()