URLMap-class {Rook}R Documentation

Class URLMap

Description

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

Methods

new(...):

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

See Also

Rhttpd.

Examples

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('<h1><a href="%s">Pong</a></h1>',req$to_url("/pong")))
            res$finish()
        },
        '/pong' = function(env){
            req <- Rook::Request$new(env)
            res <- Rook::Response$new()
            res$write(sprintf('<h1><a href="%s">Ping</a></h1>',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()
        }
    )
)
## Not run: 
s$start(quiet=TRUE)
s$browse('pingpong')

## End(Not run)
s$remove('pingpong')
## Not run: 
s$stop()

## End(Not run)
rm(s)

[Package Rook version 1.2 Index]