R: Async client for different request types

AsyncVaried {crul} | R Documentation

## Async client for different request types

### Description

Async client for different request types

### Arguments

`..., .list` | Any number of objects of class `HttpRequest()`, must supply inputs to one of these parameters, but not both

### Details

Methods

`request()`

  Execute asynchronous requests - returns: nothing, responses stored inside object, though will print messages if you choose verbose output

`requests()`

  list requests - returns: a list of `HttpRequest` objects, empty list before requests made

`responses()`

  list responses - returns: a list of `HttpResponse` objects, empty list before requests made

`parse(encoding = "UTF-8")`

  parse content - returns: character vector, empty character vector before requests made

`status_code()`

  (integer) HTTP status codes - returns: numeric vector, empty numeric vector before requests made

`status()`

  (list) HTTP status objects - returns: a list of `http_code` objects, empty list before requests made

`content()`

  raw content - returns: raw list, empty list before requests made

`times()`

  curl request times - returns: list of named numeric vectors, empty list before requests made

### Value

An object of class `AsyncVaried` with variables and methods. Responses are returned in the order they are passed in.

### See Also

Other async: `Async`

### Examples

    ## Not run:
    # pass in requests via ...
    req1 <- HttpRequest$new(
      url = "https://httpbin.org/get",
      opts = list(verbose = TRUE),
      headers = list(foo = "bar")
    )$get()
    req2 <- HttpRequest$new(url = "https://httpbin.org/post")$post()

    # Create an AsyncVaried object
    out <- AsyncVaried$new(req1, req2)

    # before you make requests, the methods return empty objects
    out$status()
    out$status_code()
    out$content()
    out$times()
    out$parse()
    out$responses()

    # make requests
    out$request()

    # access various parts
    ## http status objects
    out$status()
    ## status codes
    out$status_code()
    ## content (raw data)
    out$content()
    ## times
    out$times()
    ## parsed content
    out$parse()
    ## response objects
    out$responses()

    # pass in requests in a list via .list param
    reqlist <- list(
      HttpRequest$new(url = "https://httpbin.org/get")$get(),
      HttpRequest$new(url = "https://httpbin.org/post")$post(),
      HttpRequest$new(url = "https://httpbin.org/put")$put(),
      HttpRequest$new(url = "https://httpbin.org/delete")$delete(),
      HttpRequest$new(url = "https://httpbin.org/get?g=5")$get(),
      HttpRequest$new(
        url = "https://httpbin.org/post")$post(body = list(y = 9)),
      HttpRequest$new(
        url = "https://httpbin.org/get")$get(query = list(hello = "world"))
    )

    out <- AsyncVaried$new(.list = reqlist)
    out$request()
    out$status()
    out$status_code()
    out$content()
    out$times()
    out$parse()

    ## End(Not run)

[Package crul version 0.5.2 Index]