| Request {RestRserve} | R Documentation |
Creates Request object
Description
Called internally for handling incoming requests from Rserve side. Also useful for testing.
Public fields
pathRequest path.
methodRequest HTTP method.
headersRequest headers.
cookiesRequest cookies.
contextEnvironment to store any data. Can be used in middlewares.
content_typeRequest body content type.
bodyRequest body.
parameters_queryRequest query parameters.
parameters_bodyRequest body parameters.
parameters_pathList 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/1thenparameters_pathwill belist(job_id = "1").
It is important to understand thatparameters_pathwill be available (not empty) only after request will reach handler.
This effectively means thatparameters_pathcan be used inside handler and response middleware (but not request middleware!).filesStructure which contains positions and lengths of files for the multipart body.
decodeFunction to decode body for the specific content type.
Active bindings
idAutomatically generated UUID for each request. Read only.
dateRequest
Dateheader converted toPOSIXct.acceptSplitted
Acceptrequest header.accept_jsonRequest accepts JSON response.
accept_xmlRequest accepts XML response.
Methods
Public methods
Method new()
Creates Request object
Usage
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,
...
)Arguments
pathCharacter with requested path. Always starts with
/.methodRequest HTTP method.
parameters_queryA named list with URL decoded query parameters.
parameters_bodyA named list with URL decoded body parameters. This field is helpful when request is a urlencoded form or a multipart form.
headersRequest HTTP headers represented as named list.
bodyRequest body. Can be anything and in conjunction with
content_typedefines how HTTP body will be represented.cookiesCookies represented as named list. Note that cookies should be provided explicitly - they won't be derived from
headers.content_typeHTTP content type. Note that
content_typeshould be provided explicitly - it won't be derived fromheaders.decodeFunction to decode body for the specific content type.
...Not used at this moment.
Method set_id()
Set request id.
Usage
Request$set_id(id = uuid::UUIDgenerate(TRUE))
Arguments
idRequest id.
Method 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.
Usage
Request$reset()
Method get_header()
Get HTTP response header value. If requested header is empty returns default.
Usage
Request$get_header(name, default = NULL)
Arguments
nameHeader field name.
defaultDefault value if header does not exists.
Returns
Header field values (character string).
Method get_param_query()
Get request query parameter by name.
Usage
Request$get_param_query(name)
Arguments
nameQuery parameter name.
Returns
Query parameter value (character string).
Method get_param_body()
Get request body parameter by name.
Usage
Request$get_param_body(name)
Arguments
nameBody field name.
Returns
Body field value.
Method get_param_path()
Get templated path parameter by name.
Usage
Request$get_param_path(name)
Arguments
namePath parameter name.
Returns
Path parameter value.
Method get_file()
Extract specific file from multipart body.
Usage
Request$get_file(name)
Arguments
nameBody file name.
Returns
Raw vector with filname and content-type attributes.
Method print()
Print method.
Usage
Request$print()
Method clone()
The objects of this class are cloneable with this method.
Usage
Request$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Examples
# 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