Description Usage Details Examples
Request objects store relevant information sent from the client to the server as a part of an HTTP request. Request objects are not typically explicitly created. Instead, a request object is passed as an argument to a route handler.
1 2 3 | request()
is.request(x)
|
Request objects contain the following information.
Most often GET
or POST
, the method indicates what action to
take for a specified resource. This value may be accessed with
method
.
The uri indicates the server resource requested by the client. A request
object's uri may be accessed with uri
.
A request query is set of key value pairs following the uri. A query is
indicated by a ? and is, optionally, ended with a #. Query keys are case-
sensitive. A request object's query list may be accessed with query.
If an incoming request does not have a query string then query
will
return an empty list.
Request header fields may be accessed by treating a request object like a list. Using [ or [[, one can get a single or multiple header field values. Header fields are case-insensitive.
The body message of a request object may be retreived with body.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # not much to see here
req <- request()
print(req)
# the request object is loaded with information
# from the client
printreq <- route(
'GET',
'^/print/request$',
function(req) {
print('Request received:')
print(req)
response()
}
)
# create mockup
printreq_m <- mockup(printreq)
# now there's something to see
printreq_m('get', '/print/request')
printreq_m('get', '/print/request',
headers = list(
Accept = 'text/html',
Host = 'with the most'
)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.