response: Create an HTTP Response

Description Usage Arguments Components See Also Examples

Description

A response object represents the HTTP response returned by a route handler. A response is typically made up of a status, HTTP headers, and a body. A response body is optional.

Usage

1
response(status = 200, content_type = "text/plain", body = "")

Arguments

status

(numeric) HTTP status code, e.g. 200 for OK, 404 for Not Found

content_type

(character) MIME content type, e.g., "text/plain", "text/html".

body

(character) Body of the response

Components

status:

Set the status of a response to indicate what action, if any, the client needs to take. Otherwise a status of 2XX indicates a client request was valid and the response object contains the requested resource.

Below are descriptions for each status code class,

1xx:

Informational - Request received, continuing process

2xx:

Success - The action was successfully received, understood, and accepted

3xx:

Redirection - Further action must be taken in order to complete the request

4xx:

Client Error - The request contains bad syntax or cannot be fulfilled

5xx:

Server Error - The server failed to fulfill an apparently valid request

headers:

stub

body:

stub

See Also

route, request

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# a route to return a client-requested status
# and reason phrase
mkup <- mockup(
  route(
    'GET',
    '^\\d+',
    function(req) {
      stts <- sub('/', '', uri(req))

      res <- response()

      status(res) <- 200
      body(res) <- paste(stts, reason_phrase(stts))

      res
    }
  )
)

mkup('get', '302')
mkup('get', '203')

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