| Routing | R Documentation |
Core routing class. Do not use directly, see Ambiorix, and Router.
A Routing object.
errorError handler.
basepathBasepath, read-only.
websocketWebsocket handler.
new()Routing$new(path = "")
pathPrefix path.
Initialise
get()Routing$get(path, handler, error = NULL)
pathRoute to listen to, : defines a parameter.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
GET Method
Add routes to listen to.
app <- Ambiorix$new()
app$get("/", function(req, res){
res$send("Using {ambiorix}!")
})
if(interactive())
app$start()
put()Routing$put(path, handler, error = NULL)
pathRoute to listen to, : defines a parameter.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
PUT Method
Add routes to listen to.
patch()Routing$patch(path, handler, error = NULL)
pathRoute to listen to, : defines a parameter.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
PATCH Method
Add routes to listen to.
delete()Routing$delete(path, handler, error = NULL)
pathRoute to listen to, : defines a parameter.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
DELETE Method
Add routes to listen to.
post()Routing$post(path, handler, error = NULL)
pathRoute to listen to.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
POST Method
Add routes to listen to.
options()Routing$options(path, handler, error = NULL)
pathRoute to listen to.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
OPTIONS Method
Add routes to listen to.
all()Routing$all(path, handler, error = NULL)
pathRoute to listen to.
handlerFunction that accepts the request and returns an object
describing an httpuv response, e.g.: response().
errorHandler function to run on error.
All Methods
Add routes to listen to for all methods GET, POST, PUT, DELETE, and PATCH.
receive()Routing$receive(name, handler)
nameName of message.
handlerFunction to run when message is received.
Receive Websocket Message
app <- Ambiorix$new()
app$get("/", function(req, res){
res$send("Using {ambiorix}!")
})
app$receive("hello", function(msg, ws){
print(msg) # print msg received
# send a message back
ws$send("hello", "Hello back! (sent from R)")
})
if(interactive())
app$start()
print()Routing$print()
engine()Routing$engine(engine)
engineEngine function.
Engine to use for rendering templates.
use()Routing$use(use)
useEither a router as returned by Router, a function to use as middleware,
or a list of functions.
If a function is passed, it must accept two arguments (the request, and the response):
this function will be executed every time the server receives a request.
Middleware may but does not have to return a response, unlike other methods such as get
Note that multiple routers and middlewares can be used.
Use a router or middleware
get_routes()Routing$get_routes(routes = list(), parent = "")
routesExisting list of routes.
parentParent path.
Get the routes
get_receivers()Routing$get_receivers(receivers = list())
receiversExisting list of receivers
Get the websocket receivers
get_middleware()Routing$get_middleware(middlewares = list(), parent = "")
middlewaresExisting list of middleswares
parentParent path
Get the middleware
prepare()Routing$prepare()
Prepare routes and decomposes paths
clone()The objects of this class are cloneable with this method.
Routing$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `Routing$get`
## ------------------------------------------------
app <- Ambiorix$new()
app$get("/", function(req, res){
res$send("Using {ambiorix}!")
})
if(interactive())
app$start()
## ------------------------------------------------
## Method `Routing$receive`
## ------------------------------------------------
app <- Ambiorix$new()
app$get("/", function(req, res){
res$send("Using {ambiorix}!")
})
app$receive("hello", function(msg, ws){
print(msg) # print msg received
# send a message back
ws$send("hello", "Hello back! (sent from R)")
})
if(interactive())
app$start()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.