Description Usage Arguments Details Value See Also Examples
The function as.route
provides an alternative means of creating an
application route.
1 2 3 4 5 6 7 8 9 10 |
x |
An R object. |
directory |
System path to the folder containing the route file. |
... |
Additional arguments passed on to methods. |
If x
is a list, x
must have the following named elements:
method
, path
, and handler
.
If x
is a character vector, x
is interpreted as a file name.
The file must contain a route defined using the route
function. The
default directory for route files is "routes", but a different folder may be
specified with the directory
argument.
The S3 generic function as.route
is exported by prairie to encourage
creation of as.route.*
functions. Custom as.route
functions
allow users to coerce their classes to routes and quickly serve them over
HTTP.
A route
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # Easily reuse routes and keep applications
# modular by storing routes in separate files.
tmp <- tempfile()
writeLines(
'route("GET", "^$", function(req) response())\n',
con = tmp
)
as.route(tmp, dir = '')
file.remove(tmp)
# as.route.list is a minimal wrapper
# around route()
route(
'POST',
'^$',
function(req) {
response()
}
)
as.route(
list(
method = 'POST',
path = '^$',
handler = function(req) {
response()
}
)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.