These are convenient wrappers aroud add_headers().
content_type(type) content_type_json() content_type_xml() accept(type) accept_json() accept_xml()
| type | A mime type or a file extension. If a file extension (i.e. starts
with |
|---|
accept_json/accept_xml and
content_type_json/content_type_xml are useful shortcuts to
ask for json or xml responses or tell the server you are sending json/xml.
GET("http://httpbin.org/headers")#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 284 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-23370d84f911646ae9b8fc3e" #> } #> }#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 252 B #> { #> "headers": { #> "Accept": "application/json", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-3394b9c28cd74428b19103e0" #> } #> }#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 244 B #> { #> "headers": { #> "Accept": "text/csv", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-36a80f12e232f00a6f3b38bc" #> } #> }#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 254 B #> { #> "headers": { #> "Accept": "application/msword", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-bf01aca4d88e26c603fffb64" #> } #> }#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 324 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Type": "application/xml", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-b813110ec24737baa79f0380" #> } #> }#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 317 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Type": "text/csv", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-490ea6d06f1ce19cfe6adf7c" #> } #> }#> Response [http://httpbin.org/headers] #> Date: 2020-03-11 04:10 #> Status: 200 #> Content-Type: application/json #> Size: 324 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Content-Type": "application/xml", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.1", #> "X-Amzn-Trace-Id": "Root=1-5e686499-2b4196dade581a584e2fd486" #> } #> }