Routing | R Documentation |
Core routing class. Do not use directly, see Ambiorix, and Router.
error
Error handler.
basepath
Basepath, read-only.
websocket
Websocket handler.
new()
Routing$new(path = "")
path
Prefix path.
Initialise
get()
Routing$get(path, handler, error = NULL)
path
Route to listen to, :
defines a parameter.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler 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)
path
Route to listen to, :
defines a parameter.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler function to run on error.
PUT Method
Add routes to listen to.
patch()
Routing$patch(path, handler, error = NULL)
path
Route to listen to, :
defines a parameter.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler function to run on error.
PATCH Method
Add routes to listen to.
delete()
Routing$delete(path, handler, error = NULL)
path
Route to listen to, :
defines a parameter.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler function to run on error.
DELETE Method
Add routes to listen to.
post()
Routing$post(path, handler, error = NULL)
path
Route to listen to.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler function to run on error.
POST Method
Add routes to listen to.
options()
Routing$options(path, handler, error = NULL)
path
Route to listen to.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler function to run on error.
OPTIONS Method
Add routes to listen to.
all()
Routing$all(path, handler, error = NULL)
path
Route to listen to.
handler
Function that accepts the request and returns an object
describing an httpuv response, e.g.: response()
.
error
Handler 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)
name
Name of message.
handler
Function 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)
engine
Engine function.
Engine to use for rendering templates.
use()
Routing$use(use)
use
Either 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 = "")
routes
Existing list of routes.
parent
Parent path.
Get the routes
get_receivers()
Routing$get_receivers(receivers = list())
receivers
Existing list of receivers
Get the websocket receivers
get_middleware()
Routing$get_middleware(middlewares = list(), parent = "")
middlewares
Existing list of middleswares
parent
Parent 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)
deep
Whether 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.