Learn R Programming

RestRserve (version 0.1.5)

RestRserveResponse: Creates RestRserveResponse object (R6 class)

Description

Creates RestRserveResponse object. Useful if handler or middleware wants to return some value immediately and interrupt request-response cycle.

  • response = RestRserveResponse$new(body = "{}", content_type = "application/json", headers = character(0), status_code = 200L)

    body

    must be a character vector of length one or a raw vector. If it is a named character with a name file or tmpfile then the value is considered as a path to a file and content oh this file is served as body. The latter will be deleted once served.

    content_type

    "application/json" must be a character vector of length one

    headers

    character(0) must be a character vector - the elements will have CRLF appended. Neither Content-type nor Content-length may be used.

    status_code

    200L must be an integer

    context

    context is a hash-map (R's hashed environment) which can be used to store any data specific to the app. RestRserve itself will not interact with this field. This can be useful if you want to pass some data to response middleware.

Usage

RestRserveResponse

Arguments

Format

An object of class R6ClassGenerator of length 24.

Methods

$new(body = "{}", content_type = "application/json", headers = character(0), status_code = 200L)

Constructor for RestRserveResponse

$set_response(status_code, body = NULL, content_type = self$content_type)

facilitate in setting response. If body is not specified (NULL), provides standard default values for all standard status codes. Automatically encodes body for common content_type values: application/json, text/plain