# NOT RUN {
(x <- HttpClient$new(url = "https://httpbin.org"))
(res <- x$get())
## get the content type
res$response_headers$`content-type`
## check that the content type is text/html
res$raise_for_ct_html()
## it's def. not json
# res$raise_for_ct_json()
## give custom content type
res$raise_for_ct("text/html")
# res$raise_for_ct("application/json")
# res$raise_for_ct("foo/bar")
## check charset in addition to the media type
res$raise_for_ct_html(charset = "utf-8")
# res$raise_for_ct_html(charset = "utf-16")
# warn instead of stop
res$raise_for_ct_json(behavior = "warning")
# }
Run the code above in your browser using DataLab