R packages
- Either use suitable R package or write API call yourself
- Always check whether there is an R package that you could use!
httr
package: Tools for Working with URLs and HTTP (and write API calls)
GET(url = NULL,query=(xxx=xxx), ...)
: GET something from server (e.g., GET("http://httpbin.org/get")
)
POST()
: POST something to server (e.g., POST("http://httpbin.org/post", body = "this is a test")
)
content()
: Extract content from a request
content(GET("https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia.org/all-access/all-agents/Hadley_Wickham/daily/20170101/20170102"))
content(response, type = "text")
: Override server content type with type = "text"
- Status codes: 200 (success!), 4XX (client error), 5XX (server error)