| Response | R Documentation |
Creates response object.
bodyResponse body.
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_typeResponse body content (media) type. Will be translated
to Content-type header.
headersResponse headers.
status_codeResponse HTTP status code.
cookiesResponse cookies. Will be translated to Set-Cookie headers.
contextEnvironment to store any data. Can be used in middlewares.
encodeFunction to encode body for specific content.
statusPaste together status code and description.
new()Creates Response object
Response$new(
body = NULL,
content_type = "text/plain",
headers = list(Server = getOption("RestRserve.headers.server")),
status_code = 200L,
encode = NULL,
...
)bodyResponse body.
content_typeResponse body content (media) type.
headersResponse headers.
status_codeResponse status code.
encodeFunction to encode body for specific content.
...Not used at this moment.
reset()Resets response object. This is not useful for end user, but useful for RestRserve internals - resetting R6 class is much faster then initialize it.
Response$reset()
set_content_type()Set content type for response body.
Response$set_content_type(content_type = "text/plain")
content_typeResponse body content (media) type.
set_status_code()Set HTTP status code for response. See docs on MDN.
Response$set_status_code(code)
codeStatus code as integer number.
has_header()Determine whether or not the response header exists.
Response$has_header(name)
nameHeader field name.
Logical value.
get_header()Get HTTP response header value. If requested header is empty returns default.
Response$get_header(name, default = NULL)
nameHeader field name.
defaultDefault value if header does not exists.
Header field values (character string).
set_header()Set HTTP response header. Content-type and Content-length headers not
allowed (use content_type field instead).
Response$set_header(name, value)
nameHeader field name.
valueHeader field value.
delete_header()Unset HTTP response header.
Response$delete_header(name)
nameHeader field name.
Logical value.
append_header()Append HTTP response header. If header exists , separator will be used.
Don't use this method to set cookie (use set_cookie method instead).
Response$append_header(name, value)
nameHeader field name.
valueHeader field value.
set_date()Set Date HTTP header. See docs on MDN.
Response$set_date(dtm = Sys.time())
dtmPOSIXct value.
unset_date()Unset Date HTTP header.
Response$unset_date()
Logical value.
set_cookie()Set cookie. See docs on MDN.
Response$set_cookie( name, value, expires = NULL, max_age = NULL, domain = NULL, path = NULL, secure = NULL, http_only = NULL )
nameCookie name.
valueCookie value.
expiresCookie expires date and time (POSIXct).
max_ageMax cookie age (integer).
domainCookie domain.
pathCookie path.
secureCookie secure flag.
http_onlyCookie HTTP only flag.
unset_cookie()Unset cookie with given name.
Response$unset_cookie(name)
nameCookie name.
Logical value.
set_body()Set response body.
Response$set_body(body)
bodyResponse body.
set_response()Set response fields.
Response$set_response( status_code, body = NULL, content_type = self$content_type )
status_codeResponse HTTP status code.
bodyResponse body.
content_typecontent_type Response body content (media) type.
print()Print method.
Response$print()
clone()The objects of this class are cloneable with this method.
Response$clone(deep = FALSE)
deepWhether to make a deep clone.
Request Application
# init response
rs = Response$new()
# set body media type
rs$set_content_type("text/plain")
# set body content
rs$set_body("OK")
# set response status code
rs$set_status_code(200L)
# print response
rs
# init response
rs = Response$new()
# static file path
file_path = system.file("DESCRIPTION", package = "RestRserve")
# get last file modification timestamp
file_mtime = file.mtime(file_path)
# set body
rs$set_body(c("file" = file_path))
# set content type
rs$set_content_type("text/plain")
# set current timestamp
rs$set_date()
# set 'last-modified' header
rs$set_header("Last-Modified", as(file_mtime, "HTTPDate"))
# print response
rs
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.