# NOT RUN {
(x <- HttpClient$new(url = "https://httpbin.org"))
x$url
(res_get1 <- x$get('get'))
res_get1$content
res_get1$response_headers
res_get1$parse()
(res_get2 <- x$get('get', query = list(hello = "world")))
res_get2$parse()
library("jsonlite")
jsonlite::fromJSON(res_get2$parse())
# post request
(res_post <- x$post('post', body = list(hello = "world")))
## empty body request
x$post('post')
# put request
(res_put <- x$put('put'))
# delete request
(res_delete <- x$delete('delete'))
# patch request
(res_patch <- x$patch('patch'))
# head request
(res_head <- x$head())
# query params are URL encoded for you, so DO NOT do it yourself
## if you url encode yourself, it gets double encoded, and that's bad
(x <- HttpClient$new(url = "https://httpbin.org"))
res <- x$get("get", query = list(a = 'hello world'))
# }
Run the code above in your browser using DataLab