-
Notifications
You must be signed in to change notification settings - Fork 141
notebook.R API
Simon Urbanek edited this page Mar 20, 2015
·
7 revisions
Notebooks called via notebook.R
are evaluated (R cells only!) and the result has to be a function. That function is then called with the following arguments:
mandatory:
-
notebook
argument is set to the notebook ID - the full path piece of the url is passed as
.url
(sorry for the misnomer)
optional:
- query parameters are parsed into arguments [e.g.
?a=b
is passed as(a="b")
] - body is passed as the
.body
argument if present. Content of typeapplication/x-www-form-urlencoded
is parsed into a named character vector (a=b&c=d
is parsed intoc(a="b", c="d")
), all other types are passed as the raw vector of the body content withcontent-type
attribute storing the content type from the header. - cookies are parsed into the
.cookies
argument - dynamic paths beyond
.self
are passed as a.path.info
argument (character vector)
Probably the most trivial notebook to show what's passed:
function(...) WebResult("html", paste(capture.output(str(list(...))),
collapse="\n"), "text/plain")
Most simple GET:
$ curl https://rcloud.research.att.com/notebook.R/0a10de2ba3685cf64ea0
List of 3
$ .cookies: list()
$ .url : chr "/notebook.R/0a10de2ba3685cf64ea0"
$ notebook: chr "0a10de2ba3685cf64ea0"
GET with query:
$ curl https://rcloud.research.att.com/notebook.R/0a10de2ba3685cf64ea0?a=b
List of 4
$ a : chr "b"
$ .cookies: list()
$ .url : chr "/notebook.R/0a10de2ba3685cf64ea0"
$ notebook: chr "0a10de2ba3685cf64ea0"
GET with path info:
$ curl https://rcloud.research.att.com/notebook.R/0a10de2ba3685cf64ea0/.self/foo/bar
List of 4
$ .cookies : list()
$ .url : chr "/notebook.R/0a10de2ba3685cf64ea0/.self/foo/bar"
$ notebook : chr "0a10de2ba3685cf64ea0"
$ .path.info: chr [1:3] ".self" "foo" "bar"
POST with form:
$ curl -d a=b https://rcloud.research.att.com/notebook.R/0a10de2ba3685cf64ea0
List of 4
$ .cookies: list()
$ .body : Named chr "b"
..- attr(*, "names")= chr "a"
$ .url : chr "/notebook.R/0a10de2ba3685cf64ea0"
$ notebook: chr "0a10de2ba3685cf64ea0"
POST with form and query:
$ curl -d a=b https://rcloud.research.att.com/notebook.R/0a10de2ba3685cf64ea0?c=d
List of 5
$ c : chr "d"
$ .cookies: list()
$ .body : Named chr "b"
..- attr(*, "names")= chr "a"
$ .url : chr "/notebook.R/0a10de2ba3685cf64ea0"
$ notebook: chr "0a10de2ba3685cf64ea0"
POST with binary multiform:
$ curl -F file=foobar.html https://rcloud.research.att.com/notebook.R/0a10de2ba3685cf64ea0
List of 4
$ .cookies: list()
$ .body : atomic [1:150] 2d 2d 2d 2d ...
..- attr(*, "content-type")= chr "multipart/form-data; boundary=------------------------4997f0fbeec056f5"
$ .url : chr "/notebook.R/0a10de2ba3685cf64ea0"
$ notebook: chr "0a10de2ba3685cf64ea0"
FWIW there are tools to parse the last case on the R side - see FastRWeb::parse.multipart()