These are convenient wrappers aroud add_headers.

content_type(type)

content_type_json()

content_type_xml()

accept(type)

accept_json()

accept_xml()

Arguments

type

A mime type or a file extension. If a file extension (i.e. starts with .) will guess the mime type using guess_type.

Details

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.

Examples

GET("http://httpbin.org/headers")
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:11 #> Status: 200 #> Content-Type: application/json #> Size: 246 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }
GET("http://httpbin.org/headers", accept_json())
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:11 #> Status: 200 #> Content-Type: application/json #> Size: 214 B #> { #> "headers": { #> "Accept": "application/json", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }
GET("http://httpbin.org/headers", accept("text/csv"))
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:11 #> Status: 200 #> Content-Type: application/json #> Size: 206 B #> { #> "headers": { #> "Accept": "text/csv", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }
GET("http://httpbin.org/headers", accept(".doc"))
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:11 #> Status: 200 #> Content-Type: application/json #> Size: 216 B #> { #> "headers": { #> "Accept": "application/msword", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }
GET("http://httpbin.org/headers", content_type_xml())
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:12 #> Status: 200 #> Content-Type: application/json #> Size: 286 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Content-Type": "application/xml", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }
GET("http://httpbin.org/headers", content_type("text/csv"))
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:12 #> Status: 200 #> Content-Type: application/json #> Size: 279 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Content-Type": "text/csv", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }
GET("http://httpbin.org/headers", content_type(".xml"))
#> Response [http://httpbin.org/headers] #> Date: 2017-08-16 14:12 #> Status: 200 #> Content-Type: application/json #> Size: 286 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "gzip, deflate", #> "Connection": "close", #> "Content-Type": "application/xml", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.0" #> } #> }