| Response | R Documentation |
Response class to generate responses sent from the server.
A Response object.
statusStatus of the response, defaults to 200L.
headersNamed list of headers.
set_status()Response$set_status(status)
statusAn integer defining the status.
Set the status of the response.
send()Response$send(body, headers = NULL, status = NULL)
bodyBody of the response.
headersHTTP headers to set.
statusStatus of the response, if NULL uses self$status.
Send a plain HTML response.
sendf()Response$sendf(body, ..., headers = NULL, status = NULL)
bodyBody of the response.
...Passed to ... of sprintf.
headersHTTP headers to set.
statusStatus 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)
bodyBody of the response.
headersHTTP headers to set.
statusStatus of the response, if NULL uses self$status.
Send a plain text response.
send_file()Response$send_file(file, headers = NULL, status = NULL)
fileFile to send.
headersHTTP headers to set.
statusStatus of the response.
Send a file.
redirect()Response$redirect(path, status = NULL)
pathPath or URL to redirect to.
statusStatus of the response, if NULL uses self$status.
Redirect to a path or URL.
render()Response$render(file, data = list(), headers = NULL, status = NULL)
fileTemplate file.
dataList to fill [% tags %].
headersHTTP headers to set.
statusStatus of the response, if NULL uses self$status.
Render a template file.
json()Response$json(body, headers = NULL, status = NULL, ...)
bodyBody of the response.
headersHTTP headers to set.
statusStatus of the response, if NULL uses self$status.
...Additional named arguments passed to the serialiser.
Render an object as JSON.
csv()Response$csv(data, name = "data", status = NULL, ...)
dataData to convert to CSV.
nameName of the file.
statusStatus 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, ...)
dataData to convert to CSV.
nameName of the file.
statusStatus 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, ...)
widgetThe widget to use.
statusStatus 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)
fileTemplate file.
dataList to fill [% tags %].
headersHTTP headers to set.
statusStatus of the response, if NULL uses self$status.
Render a markdown file.
png()Response$png(file)
filePath to local file.
Send a png file
jpeg()Response$jpeg(file)
filePath to local file.
Send a jpeg file
image()Response$image(file)
filePath 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"))plotGgplot2 plot object.
...Passed to ggplot2::ggsave()
typeType of image to save.
Ggplot2
print()Response$print()
set()Response$set(name, value)
nameString. Name of the variable.
valueValue of the variable.
Set Data
Invisible returns self.
get()Response$get(name)
nameString. Name of the variable to get.
Get data
header()Response$header(name, value)
nameString. Name of the header.
valueValue 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)
nameName of the header to return.
Get a header
Returns a single header currently, NULL if not set.
set_headers()Response$set_headers(headers)
headersA named list of headers to set.
Set headers
set_header()Response$set_header(name, value)
nameName of the header.
valueValue to set.
Set a Header
Invisible returns self.
pre_render_hook()Response$pre_render_hook(hook)
hookA 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)
hookA function to run after the rendering of HTML. It should accept at least 3 arguments:
self: The Response 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")
)nameString. Name of the cookie.
valuevalue of the cookie.
expiresExpiry, 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_ageIndicates 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.
domainDefines 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.
pathIndicates the path that must exist in the requested URL for the browser to send the Cookie header.
secureIndicates 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_onlyForbids JavaScript from accessing the cookie, for example, through the document.cookie property.
same_siteControls 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)
nameName 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)
deepWhether to make a deep clone.
if (interactive()) {
library(ambiorix)
app <- Ambiorix$new()
app$get("/", function(req, res) {
# print(res)
res$send("Using {ambiorix}!")
})
app$start()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.