Router | R Documentation |
Web server.
ambiorix::Routing
-> Router
error
500 response when the route errors, must a handler function that accepts the request and the response, by default uses response_500()
.
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()
new()
Router$new(path)
path
The base path of the router.
Define the base route.
print()
Router$print()
clone()
The objects of this class are cloneable with this method.
Router$clone(deep = FALSE)
deep
Whether to make a deep clone.
# 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.