Public methods
Method new()
Usage
Routing$new(path = "")
Arguments
path
Prefix path.
Details
Initialise
Method get()
Usage
Routing$get(path, handler, error = NULL)
Arguments
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.
Details
GET Method
Add routes to listen to.
Examples
app <- Ambiorix$new()
app$get("/", function(req, res){
res$send("Using {ambiorix}!")
})
if(interactive())
app$start()
Method put()
Usage
Routing$put(path, handler, error = NULL)
Arguments
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.
Details
PUT Method
Add routes to listen to.
Method patch()
Usage
Routing$patch(path, handler, error = NULL)
Arguments
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.
Details
PATCH Method
Add routes to listen to.
Method delete()
Usage
Routing$delete(path, handler, error = NULL)
Arguments
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.
Details
DELETE Method
Add routes to listen to.
Method post()
Usage
Routing$post(path, handler, error = NULL)
Arguments
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.
Details
POST Method
Add routes to listen to.
Method options()
Usage
Routing$options(path, handler, error = NULL)
Arguments
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.
Details
OPTIONS Method
Add routes to listen to.
Method all()
Usage
Routing$all(path, handler, error = NULL)
Arguments
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.
Details
All Methods
Add routes to listen to for all methods GET
, POST
, PUT
, DELETE
, and PATCH
.
Method receive()
Usage
Routing$receive(name, handler)
Arguments
name
Name of message.
handler
Function to run when message is received.
Details
Receive Websocket Message
Examples
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()
Method print()
Usage
Routing$print()
Details
Print
Method use()
Usage
Routing$use(use)
Arguments
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.
Details
Use a router or middleware
Method get_routes()
Usage
Routing$get_routes()
Details
Get the routes
Method get_receivers()
Usage
Routing$get_receivers()
Details
Get the receivers
Method get_middleware()
Usage
Routing$get_middleware()
Details
Get the middleware
Method clone()
The objects of this class are cloneable with this method.
Usage
Routing$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.