GET
Code Description Output
r <- GET('http://httpbin.org/get') Запит методом GET Response [http://httpbin.org/get]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 329 B
{
"args": {},
"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.1"
},
"origin": "193.108.122.245",
...
content(r) Вивід вмісту отриманої відповіді на запит $count
[1] 1

$`next`
NULL

$previous
NULL

$results
$results[[1]]
$results[[1]]$name
[1] "Darth Vader"

$results[[1]]$height
[1] "202"

$results[[1]]$mass
[1] "136"

$results[[1]]$hair_color
[1] "none"

$results[[1]]$skin_color
[1] "white"

$results[[1]]$eye_color
[1] "yellow"

$results[[1]]$birth_year
[1] "41.9BBY"

$results[[1]]$gender
[1] "male"

$results[[1]]$homeworld
[1] "http://swapi.co/api/planets/1/"

$results[[1]]$films
$results[[1]]$films[[1]]
[1] "http://swapi.co/api/films/2/"

$results[[1]]$films[[2]]
[1] "http://swapi.co/api/films/6/"

$results[[1]]$films[[3]]
[1] "http://swapi.co/api/films/3/"

$results[[1]]$films[[4]]
[1] "http://swapi.co/api/films/1/"


$results[[1]]$species
$results[[1]]$species[[1]]
[1] "http://swapi.co/api/species/1/"


$results[[1]]$vehicles
list()

$results[[1]]$starships
$results[[1]]$starships[[1]]
[1] "http://swapi.co/api/starships/13/"


$results[[1]]$created
[1] "2014-12-10T15:18:20.704000Z"

$results[[1]]$edited
[1] "2014-12-20T21:17:50.313000Z"

$results[[1]]$url
[1] "http://swapi.co/api/people/4/"


status_code(r) Виід статусу запиту [1] 200
headers(r) NA $date
[1] "Tue, 19 Sep 2017 10:12:33 GMT"

$`content-type`
[1] "application/json"

$`transfer-encoding`
[1] "chunked"

$connection
[1] "keep-alive"

$`set-cookie`
[1] "__cfduid=d1886bb579754ca29dda9397e399962a51505815953; expires=Wed, 19-Sep-18 10:12:33 GMT; path=/; domain=.swapi.co; HttpOnly"

$allow
[1] "GET, HEAD, OPTIONS"

$`x-frame-options`
[1] "SAMEORIGIN"

$vary
[1] "Accept, Cookie"

$etag
[1] "W/\"aeb3c302f6866c5a0a548eaafa967d61\""

$via
[1] "1.1 vegur"

$server
[1] "cloudflare-nginx"

$`cf-ray`
[1] "3a0bc46c623e8b94-KBP"

$`content-encoding`
[1] "gzip"

attr(,"class")
[1] "insensitive" "list"
str(content(r)) Структура вмісту NULL
stop_for_status(r) Зупинка сесії Response [http://swapi.co/api/people/?search=vader]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 608 B
content(r, 'text') Вивід контенту відповіді на запит у текстовому форматі [1] "{\"count\":1,\"next\":null,\"previous\":null,\"results\":[{\"name\":\"Darth Vader\",\"height\":\"202\",\"mass\":\"136\",\"hair_color\":\"none\",\"skin_color\":\"white\",\"eye_color\":\"yellow\",\"birth_year\":\"41.9BBY\",\"gender\":\"male\",\"homeworld\":\"http://swapi.co/api/planets/1/\",\"films\":[\"http://swapi.co/api/films/2/\",\"http://swapi.co/api/films/6/\",\"http://swapi.co/api/films/3/\",\"http://swapi.co/api/films/1/\"],\"species\":[\"http://swapi.co/api/species/1/\"],\"vehicles\":[],\"starships\":[\"http://swapi.co/api/starships/13/\"],\"created\":\"2014-12-10T15:18:20.704000Z\",\"edited\":\"2014-12-20T21:17:50.313000Z\",\"url\":\"http://swapi.co/api/people/4/\"}]}"
content(r, 'text', encoding = 'ISO-8859-1') Вивід контенту відповіді на запит у текстовому форматі з кодуванням [1] "{\"count\":1,\"next\":null,\"previous\":null,\"results\":[{\"name\":\"Darth Vader\",\"height\":\"202\",\"mass\":\"136\",\"hair_color\":\"none\",\"skin_color\":\"white\",\"eye_color\":\"yellow\",\"birth_year\":\"41.9BBY\",\"gender\":\"male\",\"homeworld\":\"http://swapi.co/api/planets/1/\",\"films\":[\"http://swapi.co/api/films/2/\",\"http://swapi.co/api/films/6/\",\"http://swapi.co/api/films/3/\",\"http://swapi.co/api/films/1/\"],\"species\":[\"http://swapi.co/api/species/1/\"],\"vehicles\":[],\"starships\":[\"http://swapi.co/api/starships/13/\"],\"created\":\"2014-12-10T15:18:20.704000Z\",\"edited\":\"2014-12-20T21:17:50.313000Z\",\"url\":\"http://swapi.co/api/people/4/\"}]}"
str(content(r, 'parsed')) Структура вмісту в форматі NULL
r <- GET('http://httpbin.org/get', query = list(key1 = 'value1', key2 = 'value2')) Запит GET через query Response [http://httpbin.org/get?key1=value1&key2=value2]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 400 B
{
"args": {
"key1": "value1",
"key2": "value2"
},
"headers": {
"Accept": "application/json, text/xml, application/xml, */*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Host": "httpbin.org",
...
r <- GET('http://httpbin.org/get', add_headers(Name = 'Hadley')) Запит GET з додаванням заголовків Response [http://httpbin.org/get]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 352 B
{
"args": {},
"headers": {
"Accept": "application/json, text/xml, application/xml, */*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Host": "httpbin.org",
"Name": "Hadley",
"User-Agent": "libcurl/7.54.0 r-curl/2.8.1 httr/1.3.1"
},
...
POST
Code Description Output
POST Запит методом POST function (url = NULL, config = list(), ..., body = NULL, encode = c("multipart",
"form", "json", "raw"), handle = NULL)
{
encode <- match.arg(encode)
hu <- handle_url(handle, url, ...)
req <- request_build("POST", hu$url, body_config(body, match.arg(encode)),
as.request(config), ...)
request_perform(req, hu$handle$handle)
}
r <- POST('http://httpbin.org/post', body = list(a = '1', b = '2', c = '3')) Типовий запит POST-методом Response [http://httpbin.org/post]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 564 B
{
"args": {},
"data": "",
"files": {},
"form": {
"a": "1",
"b": "2",
"c": "3"
},
"headers": {
...
POST('http://httpbin.org/post', body = list(a = '1', b = '2', c = '3'), encode = 'multipart', verbose()) # the default Запит POST з кодуванням Response [http://httpbin.org/post]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 564 B
{
"args": {},
"data": "",
"files": {},
"form": {
"a": "1",
"b": "2",
"c": "3"
},
"headers": {
...
POST('http://httpbin.org/post', body = list(a = '1', b = '2', c = '3'), encode = 'form', verbose()) Запит POST з кодуванням Response [http://httpbin.org/post]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 526 B
{
"args": {},
"data": "",
"files": {},
"form": {
"a": "1",
"b": "2",
"c": "3"
},
"headers": {
...
POST('http://httpbin.org/post', body = list(a = '1', b = '2', c = '3'), encode = 'json', verbose()) Запит POST з кодуванням Response [http://httpbin.org/post]
Date: 2017-09-19 10:12
Status: 200
Content-Type: application/json
Size: 544 B
{
"args": {},
"data": "{\"a\":\"1\",\"b\":\"2\",\"c\":\"3\"}",
"files": {},
"form": {},
"headers": {
"Accept": "application/json, text/xml, application/xml, */*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "25",
...