Learn R Programming

Rook (version 1.2)

URLMap-class: Class URLMap

Description

A Rook application that maps url paths to other Rook applications.

Arguments

Methods

new(...):

Creates a Rook application. All arguments must be Rook applications and named as in the example.

See Also

Rhttpd.

Examples

Run this code
s <- Rhttpd$new()
s$add(
    name="pingpong",
    app=Rook::URLMap$new(
        '/ping' = function(env){
            req <- Rook::Request$new(env)
            res <- Rook::Response$new()
            res$write(sprintf('Pong',req$to_url("/pong")))
            res$finish()
        },
        '/pong' = function(env){
            req <- Rook::Request$new(env)
            res <- Rook::Response$new()
            res$write(sprintf('Ping',req$to_url("/ping")))
            res$finish()
        },
        '/?' = function(env){
            req <- Rook::Request$new(env)
            res <- Rook::Response$new()
            res$redirect(req$to_url('/pong'))
            res$finish()
        }
    )
)
if (FALSE) {
s$start(quiet=TRUE)
s$browse('pingpong')
}
s$remove('pingpong')
if (FALSE) {
s$stop()
}
rm(s)

Run the code above in your browser using DataLab