Learn R Programming

request (version 0.1.0)

http: Make a HTTP request

Description

Make a HTTP request

Usage

http(req, method = "GET")
http_client(req)

Arguments

req
A req class object
method
(character) Pick which HTTP method to use. Only GET and POST for now. Default: GET

Details

By default, a GET request is made. Will fix this soon to easily allow a different HTTP verb.

The http function makes the request and gives back the parsed result. Whereas, the http_client function makes the request, but gives back the raw R6 class object, which you can inspect all parts of, modify, etc.

Examples

Run this code
## Not run: 
# # high level - http()
# api('https://api.github.com/') %>%
#   api_path(repos, ropensci, rgbif, commits) %>%
#   http()
# 
# # low level - http_client()
# res <- api('https://api.github.com/') %>%
#   api_path(repos, ropensci, rgbif, commits) %>%
#   http_client()
# res$count()
# res$body()
# res$status()
# res$result
# res$links
# res$parse()
# 
# # Specify HTTP verb
# api("http://httpbin.org/post") %>%
#    api_body(x = "A simple text string") %>%
#    http("POST")
# ## End(Not run)

Run the code above in your browser using DataLab