ropensci / crul

R6 based http client for R (for developers)
https://docs.ropensci.org/crul
Other
107 stars 17 forks source link

helpers for content type checking #119

Closed sckott closed 4 years ago

sckott commented 5 years ago

via https://github.com/ropensci/pangaear/issues/68 - seems like a method on the HttpResponse could be helpful to check response content types:

sckott commented 5 years ago

pseudo-code

x <- HttpClient$new('https://httpbin.org/get?foo=bar')

maybe methods like $raise_for_status(), but for the most common content types

x$raise_for_ct_xml() # == text/xml
x$raise_for_ct_json() # == application/json
x$raise_for_ct_html() # == text/html

where you could choose to stop or warn

x$raise_for_ct_json(condition = "warning") # options: stop, warning

or you could pass any string to customize the match

x$raise_for_ct("application/vnd.citationstyles.csl+json")