• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

R/H20-Oct-2014-1,7011,512

inst/H06-May-2014-808583

man/H20-Oct-2014-984897

src/H20-Oct-2014-6351

DESCRIPTIONH A D20-Oct-2014606 1918

MD5H A D20-Oct-20143.3 KiB6059

NAMESPACEH A D06-May-2014548 1817

README.mdH A D06-May-20144 KiB12896

README.md

1Rook: A web server interface for R
2=======================================
3
4This pecification defines the interface between web servers and R applications.
5
6Rook applications
7-----------------
8
9A Rook application is an R reference class object that implements a 'call'
10method or an R closure that takes exactly one argument, an environment,
11and returns a list with three named elements: the 'status', the 'headers',
12and the 'body'.
13
14Hello World
15-----------
16
17Here is a basic Rook application as a closure that implements 'hello world':
18
19    function(env){
20	body = paste('<h1>Hello World! This is Rook',env$rook.version,'.</h1>')
21	list(
22	    status = 200L,
23	    headers = list(
24		'Content-Type' = 'text/html'
25	    ),
26	    body = body
27	)
28    }
29
30And the equivalent referenc class example:
31
32    setRefClass(
33	'HelloWorld',
34	methods = list(
35	    call = function(env){
36		body = paste('<h1>Hello World! This is Rook',env$rook.version,'.</h1>')
37		list(
38		    status = 200L,
39		    headers = list(
40			'Content-Type' = 'text/html'
41		    ),
42		    body = body
43		)
44	    }
45	)
46    )
47
48The Environment
49---------------
50
51The environment argument is a true R environment object which the
52application is free to modify. It is required to contain the following
53variables:
54
55- REQUEST_METHOD: The HTTP request method, such as "GET" or "POST". This
56    cannot ever be an empty string, and so is always required.
57
58- SCRIPT_NAME:	The initial portion of the request URL‘s "path" that
59    corresponds to the application object, so that the application knows
60    its virtual "location". This may be an empty string, if the application
61    corresponds to the "root" of the server.
62
63- PATH_INFO:  The remainder of the request URL‘s "path", designating the
64    virtual "location" of the request‘s target within the application. This
65    may be an empty string, if the request URL targets the application root
66    and does not have a trailing slash. This value may be percent-encoded
67    when I originating from a URL.
68
69- QUERY_STRING:	The portion of the request URL that follows the ?,
70    if any. May be empty, but is always required!
71
72- SERVER_NAME, SERVER_PORT:   When combined with SCRIPT_NAME and PATH_INFO,
73    these variables can be used to complete the URL. Note, however, that
74    HTTP_HOST, if present, should be used in preference to SERVER_NAME for
75    reconstructing the request URL. SERVER_NAME and SERVER_PORT can never
76    be empty strings, and so are always required.
77
78- HTTP_ Variables:    Variables corresponding to the client-supplied
79    HTTP request headers (i.e., variables whose names begin with HTTP_). The
80    presence or absence of these variables should correspond with the presence
81    or absence of the appropriate HTTP header in the request.
82
83In addtion, the environment must include the following Rook-specific variables:
84
85- rook.version:	    This version of Rook.
86- rook.url_scheme:    http or https, depending on the request URL.
87- rook.input:	    See below, the input stream.
88- rook.errors:	    See below, the error stream.
89
90The Input Stream
91----------------
92
93The rook.input variable must contain an object created from a reference
94class and respond to read_lines, read, and rewind:
95
96read_lines: takes one argument, the number of lines to read. Includes partial ending line.
97read: takes one argument, the number of bytes to read. Returns a raw vector.
98rewind: Rewinds the input stream back to the beginning.
99
100The Error Stream
101----------------
102
103The rook.error variable must contain an object created from a reference
104class and must respond to flush and cat:
105
106flush: called with no arguments and makes the error stream immediately appear.
107cat: called with the same arguments as R's cat without the file and append argument.
108
109The Response
110============
111
112The Status
113----------
114
115This is an HTTP status value and must be greater than or equal to 100.
116
117The Headers
118-----------
119
120This is a named list that contains string values only corresponding to valid HTTP headers.
121
122The Body
123--------
124
125This is either a character or raw vector. If the character vector is
126named with value 'file' then value of the vector is interpreted as the
127location of a file.
128