Learn R Programming

Rook (version 1.2)

Brewery-class: Class Brewery

Description

A Middleware class for mapping URLs to a directory of files that are subsequently passed to brew. When a file is brewed, the two variables req (an object of class Request) and res (an object of class Response) are available for use.

Arguments

Methods

new(url,root,...):

url is a character string or regexp on which to match, root is the name of the directory where brew files reside. Named arguments can be passed in via ... and will be available within the scope of each brewed file.

See Also

Rhttpd, Builder, Redirect, and brew.

Examples

Run this code

#
# This application runs any file found in tempdir() through brew.
#
s <- Rhttpd$new()
if (FALSE) {
s$start(quiet=TRUE)
}
cat("Random Number: <%=rnorm(1)%>",
    file=file.path(tempdir(),"index.html"))
s$add(name="random",
    app=Builder$new(
        Brewery$new(url="/",root=tempdir()),
        Redirect$new("/index.html")
    )
)
if (FALSE) {
s$browse('random') # Opens a browser window to the app.
}
file.remove(file.path(tempdir(),"index.html"))
s$remove(all=TRUE)
rm(s)

Run the code above in your browser using DataLab