Router: Router

RouterR Documentation

Router

Description

Web server.

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

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

Print


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()


devOpifex/ambiorix documentation built on Oct. 15, 2024, 10:21 p.m.