Called internally for handling incoming requests from Rserve side. Also useful for testing.
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/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!).
filesStructure which contains positions and lengths of files for the multipart body.
decodeFunction to decode body for the specific content type.
idAutomatically generated UUID for each request. Read only.
dateRequest Date header converted to POSIXct.
acceptSplitted Accept request header.
accept_jsonRequest accepts JSON response.
accept_xmlRequest accepts XML response.
new()Creates Request object
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_type defines 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_type
should be provided explicitly - it won't be derived from headers.
decodeFunction to decode body for the specific content type.
...Not used at this moment.
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.
# 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
#> [1] "f0d4d818-03bd-11f0-bf36-129e97996b15"
# get content accept
rq$accept
#> [1] "*/*"
# get request content type
rq$content_type
#> NULL
# get header by name (lower case)
rq$get_header("custom-field")
#> [1] "value"
# get query param by name
rq$get_param_query("param1")
#> [1] "value1"
# print request
rq
#> <RestRserve Request>
#> method: GET
#> path: /
#> accept: */*
#> content-type:
#> <Query Parameters>
#> param1: value1
#> param2: value2
#> <Headers>
#> content-encoding: identity
#> custom-field: value
#> <Cookies>
#> sessionid: 1