body: HTTP Message Body

Description Usage Arguments Details Value Examples

Description

Get the message body of a request or response or set the body of a response.

Usage

1
2
3
body(x)

body(x) <- value

Arguments

x

An R object.

value

The response body, if JSON the Content-Type is set to application/json.

Details

For more information about HTTP requests please refer to the Request section of www.w3.org.

Value

body resturns a character string if the request or response contains a message body, otherwise NULL.

body<- invisibly returns the response.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
transmog <- route(
  'POST',
  '^transmogrify/json$',
  function(req) {
    res <- response()

    # get body of request
    raw_body <- body(req)
    data <- jsonlite::fromJSON(raw_body)

    mogrified <- lapply(
      data,
      function(col) paste0(as.character(col), '!!!')
    )

    status(res) <- 200
    body(res) <- as.json(mogrified)

    res
  }
)

nteetor/prairie documentation built on May 24, 2019, 9:56 a.m.