Router {ambiorix} | R Documentation |
Router
Description
Web server.
Value
A Router object.
Super class
ambiorix::Routing
-> Router
Public fields
error
500 response when the route errors, must a handler function that accepts the request and the response, by default uses
response_500()
.
Methods
Public methods
Inherited methods
ambiorix::Routing$all()
ambiorix::Routing$delete()
ambiorix::Routing$engine()
ambiorix::Routing$get()
ambiorix::Routing$get_middleware()
ambiorix::Routing$get_receivers()
ambiorix::Routing$get_routes()
ambiorix::Routing$options()
ambiorix::Routing$patch()
ambiorix::Routing$post()
ambiorix::Routing$prepare()
ambiorix::Routing$put()
ambiorix::Routing$receive()
ambiorix::Routing$use()
Method new()
Usage
Router$new(path)
Arguments
path
The base path of the router.
Details
Define the base route.
Method print()
Usage
Router$print()
Details
Method clone()
The objects of this class are cloneable with this method.
Usage
Router$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
# log
logger <- new_log()
# router
# create router
router <- Router$new("/users")
router$get("/", function(req, res){
res$send("List of users")
})
router$get("/:id", function(req, res){
logger$log("Return user id:", req$params$id)
res$send(req$params$id)
})
router$get("/:id/profile", function(req, res){
msg <- sprintf("This is the profile of user #%s", req$params$id)
res$send(msg)
})
# core app
app <- Ambiorix$new()
app$get("/", function(req, res){
res$send("Home!")
})
# mount the router
app$use(router)
if(interactive())
app$start()
[Package ambiorix version 2.2.0 Index]