Response | R Documentation |
Response class to generate responses sent from the server.
status
Status of the response, defaults to 200L
.
headers
Named list of headers.
set_status()
Response$set_status(status)
status
An integer defining the status.
Set the status of the response.
send()
Response$send(body, headers = NULL, status = NULL)
body
Body of the response.
headers
HTTP headers to set.
status
Status of the response, if NULL
uses self$status
.
Send a plain HTML response.
sendf()
Response$sendf(body, ..., headers = NULL, status = NULL)
body
Body of the response.
...
Passed to ...
of sprintf
.
headers
HTTP headers to set.
status
Status of the response, if NULL
uses self$status
.
Send a plain HTML response, pre-processed with sprintf.
text()
Response$text(body, headers = NULL, status = NULL)
body
Body of the response.
headers
HTTP headers to set.
status
Status of the response, if NULL
uses self$status
.
Send a plain text response.
send_file()
Response$send_file(file, headers = NULL, status = NULL)
file
File to send.
headers
HTTP headers to set.
status
Status of the response.
Send a file.
redirect()
Response$redirect(path, status = NULL)
path
Path or URL to redirect to.
status
Status of the response, if NULL
uses self$status
.
Redirect to a path or URL.
render()
Response$render(file, data = list(), headers = NULL, status = NULL)
file
Template file.
data
List to fill [% tags %]
.
headers
HTTP headers to set.
status
Status of the response, if NULL
uses self$status
.
Render a template file.
json()
Response$json(body, headers = NULL, status = NULL, ...)
body
Body of the response.
headers
HTTP headers to set.
status
Status of the response, if NULL
uses self$status
.
...
Additional arguments passed to the serialiser.
Render an object as JSON.
csv()
Response$csv(data, name = "data", status = NULL, ...)
data
Data to convert to CSV.
name
Name of the file.
status
Status of the response, if NULL
uses self$status
.
...
Additional arguments passed to readr::format_csv()
.
Sends a comma separated value file
tsv()
Response$tsv(data, name = "data", status = NULL, ...)
data
Data to convert to CSV.
name
Name of the file.
status
Status of the response, if NULL
uses self$status
.
...
Additional arguments passed to readr::format_tsv()
.
Sends a tab separated value file
htmlwidget()
Response$htmlwidget(widget, status = NULL, ...)
widget
The widget to use.
status
Status of the response, if NULL
uses self$status
.
...
Additional arguments passed to htmlwidgets::saveWidget()
.
Sends an htmlwidget.
md()
Response$md(file, data = list(), headers = NULL, status = NULL)
file
Template file.
data
List to fill [% tags %]
.
headers
HTTP headers to set.
status
Status of the response, if NULL
uses self$status
.
Render a markdown file.
png()
Response$png(file)
file
Path to local file.
Send a png file
jpeg()
Response$jpeg(file)
file
Path to local file.
Send a jpeg file
image()
Response$image(file)
file
Path to local file.
Send an image
Similar to png
and jpeg
methods but guesses correct method
based on file extension.
ggplot2()
Response$ggplot2(plot, ..., type = c("png", "jpeg"))
plot
Ggplot2 plot object.
...
Passed to ggplot2::ggsave()
type
Type of image to save.
Ggplot2
print()
Response$print()
set()
Response$set(name, value)
name
Name of the variable.
value
Value of the variable.
Set Data
Invisible returns self.
get()
Response$get(name)
name
Name of the variable to get.
Get data
header()
Response$header(name, value)
name, value
Name and value of the header.
Add headers to the response.
Invisibly returns self.
header_content_json()
Response$header_content_json()
Set Content Type to JSON
Invisibly returns self.
header_content_html()
Response$header_content_html()
Set Content Type to HTML
Invisibly returns self.
header_content_plain()
Response$header_content_plain()
Set Content Type to Plain Text
Invisibly returns self.
header_content_csv()
Response$header_content_csv()
Set Content Type to CSV
Invisibly returns self.
header_content_tsv()
Response$header_content_tsv()
Set Content Type to TSV
Invisibly returns self.
get_headers()
Response$get_headers()
Get headers Returns the list of headers currently set.
get_header()
Response$get_header(name)
name
Name of the header to return.
Get a header
Returns a single header currently, NULL
if not set.
set_headers()
Response$set_headers(headers)
headers
A named list of headers to set.
Set headers
set_header()
Response$set_header(name, value)
name
Name of the header.
value
Value to set.
Set a Header
Invisible returns self.
pre_render_hook()
Response$pre_render_hook(hook)
hook
A function that accepts at least 4 arguments:
self
: The Request
class instance.
content
: File content a vector of character string,
content of the template.
data
: list
passed from render
method.
ext
: File extension of the template file.
This function is used to add pre-render hooks to the render
method. The function should return an object of class
responsePreHook
as obtained by pre_hook()
.
This is meant to be used by middlewares to, if necessary,
pre-process rendered data.
Include ...
in your hook
to ensure it will handle
potential updates to hooks in the future.
Add a pre render hook.
Runs before the render
and send_file
method.
Invisible returns self.
post_render_hook()
Response$post_render_hook(hook)
hook
A function to run after the rendering of HTML. It should accept at least 3 arguments:
self
: The Request
class instance.
content
: File content a vector of character string,
content of the template.
ext
: File extension of the template file.
Include ...
in your hook
to ensure it will handle
potential updates to hooks in the future.
Post render hook.
Invisible returns self.
cookie()
Response$cookie( name, value, expires = getOption("ambiorix.cookie.expire"), max_age = getOption("ambiorix.cookie.maxage"), domain = getOption("ambiorix.cookie.domain"), path = getOption("ambiorix.cookie.path", "/"), secure = getOption("ambiorix.cookie.secure", TRUE), http_only = getOption("ambiorix.cookie.httponly", TRUE), same_site = getOption("ambiorix.cookie.savesite") )
name
Name of the cookie.
value
value of the cookie.
expires
Expiry, if an integer assumes it's the number of seconds
from now. Otherwise accepts an object of class POSIXct
or Date
.
If a character
string then it is set as-is and not pre-processed.
If unspecified, the cookie becomes a session cookie. A session finishes
when the client shuts down, after which the session cookie is removed.
max_age
Indicates the number of seconds until the cookie expires.
A zero or negative number will expire the cookie immediately.
If both expires
and max_age
are set, the latter has precedence.
domain
Defines the host to which the cookie will be sent. If omitted, this attribute defaults to the host of the current document URL, not including subdomains.
path
Indicates the path that must exist in the requested URL for the browser to send the Cookie header.
secure
Indicates that the cookie is sent to the server only when a request is made with the https: scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
http_only
Forbids JavaScript from accessing the cookie, for example, through the document.cookie property.
same_site
Controls whether or not a cookie is sent with cross-origin
requests, providing some protection against cross-site request forgery
attacks (CSRF). Accepts Strict
, Lax
, or None
.
Set a cookie
Overwrites existing cookie of the same name
.
Invisibly returns self.
clear_cookie()
Response$clear_cookie(name)
name
Name of the cookie to clear.
Clear a cookie Clears the value of a cookie.
Invisibly returns self.
clone()
The objects of this class are cloneable with this method.
Response$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.