knitr::opts_chunk$set(echo = TRUE,
                      comment = "      ##",
                      error = TRUE,
                      collapse = TRUE)
# foo1 will be a function
library(knitr)
knit_hooks$set(foo1 = function(before, options, envir) {
  if (before) {
    paste0( '\\footnotesize _I appear before a chunk!_\n\n', '\\rule{3cm}{.4pt}')
  } else {
    '\\normalsize  \n\n_I am after a chunk..._'
  }
})

Shift in thinking:

Normal workflow: acquire database/cleanup/analyis

Consider a different way: R to extract specific pieces of information from a resource.

Window to otherwise closed software.

Most websites are closed software: You can not poke around in the internals. API is way to open a close software system in specific ways and to specific users.

First, quick Examples with command line tool: cURL


\centerline{\rule{3cm}{.4pt}}

More About RESTFUL APIs


\rule{3cm}{.4pt}

To use APIs, what do you really need to know?



Creating APIs.


knitr::knit_exit()

We know some of the plumbing: HTTP, API documentation, CURL ...

Finally, Do this in R, httr2:

https://httr2.r-lib.org

show httpbin.org show github.com

EXAMPLE: Basic GET in R


One issue not to overlook: 3rd party Security


So far, the user has been you - the Developer. What if you want others to

use app? They are going to give their username/password to your app.


Reference and Further Reading (

EXAMPLE Use Github uses token (PAT) in R.

New problem: each API server is different!

(Quote: httr2:: docs)

EXAMPLES: Many (follow httr2:: vignette) + Google, Youtube ...



https://github.com/jimrothstein/docs/blob/master/misc_files/001_R_stats_tech_reading.md

{
file <- "000_TALK_CURL.Rmd"
file  <- normalizePath(file)
file
}
rmarkdown::render(file)


jimrothstein/yt_api documentation built on Nov. 5, 2022, 8:05 p.m.