Learn R Programming

ambiorix (version 2.2.0)

Router: Router

Description

Web server.

Arguments

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

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

Run this code
# 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()

Run the code above in your browser using DataLab