Request | R Documentation |
Called internally for handling incoming requests from Rserve side. Also useful for testing.
path
Request path.
method
Request HTTP method.
headers
Request headers.
cookies
Request cookies.
context
Environment to store any data. Can be used in middlewares.
content_type
Request body content type.
body
Request body.
parameters_query
Request query parameters.
parameters_body
Request body parameters.
parameters_path
List of parameters extracted from templated path
after routing. For example if we have some handler listening at
/job/{job_id}
and we are receiving request at /job/1
then
parameters_path
will be list(job_id = "1")
.
It is important to understand that parameters_path
will be available
(not empty) only after request will reach handler.
This effectively means that parameters_path
can be used inside handler
and response middleware (but not request middleware!).
files
Structure which contains positions and lengths of files for the multipart body.
decode
Function to decode body for the specific content type.
id
Automatically generated UUID for each request. Read only.
date
Request Date
header converted to POSIXct
.
accept
Splitted Accept
request header.
accept_json
Request accepts JSON response.
accept_xml
Request accepts XML response.
new()
Creates Request object
Request$new( path = "/", method = c("GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"), parameters_query = list(), parameters_body = list(), headers = list(), body = NULL, cookies = list(), content_type = NULL, decode = NULL, ... )
path
Character with requested path. Always starts with /
.
method
Request HTTP method.
parameters_query
A named list with URL decoded query parameters.
parameters_body
A named list with URL decoded body parameters. This field is helpful when request is a urlencoded form or a multipart form.
headers
Request HTTP headers represented as named list.
body
Request body. Can be anything and in conjunction with
content_type
defines how HTTP body will be represented.
cookies
Cookies represented as named list. Note that cookies
should be provided explicitly - they won't be derived from headers
.
content_type
HTTP content type. Note that content_type
should be provided explicitly - it won't be derived from headers
.
decode
Function to decode body for the specific content type.
...
Not used at this moment.
set_id()
Set request id.
Request$set_id(id = uuid::UUIDgenerate(TRUE))
id
Request id.
reset()
Resets request object. This is not useful for end user, but useful for RestRserve internals - resetting R6 class is much faster then initialize it.
Request$reset()
get_header()
Get HTTP response header value. If requested header is empty returns default
.
Request$get_header(name, default = NULL)
name
Header field name.
default
Default value if header does not exists.
Header field values (character string).
get_param_query()
Get request query parameter by name.
Request$get_param_query(name)
name
Query parameter name.
Query parameter value (character string).
get_param_body()
Get request body parameter by name.
Request$get_param_body(name)
name
Body field name.
Body field value.
get_param_path()
Get templated path parameter by name.
Request$get_param_path(name)
name
Path parameter name.
Path parameter value.
get_file()
Extract specific file from multipart body.
Request$get_file(name)
name
Body file name.
Raw vector with filname
and content-type
attributes.
print()
Print method.
Request$print()
clone()
The objects of this class are cloneable with this method.
Request$clone(deep = FALSE)
deep
Whether to make a deep clone.
Response Application
# init simply request
rq = Request$new(
path = "/",
parameters_query = list(
"param1" = "value1",
"param2" = "value2"
),
headers = list(
"Content-encoding" = "identity",
"Custom-field" = "value"
),
cookies = list(
"sessionId" = "1"
)
)
# get request UUID
rq$id
# get content accept
rq$accept
# get request content type
rq$content_type
# get header by name (lower case)
rq$get_header("custom-field")
# get query param by name
rq$get_param_query("param1")
# print request
rq
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.