A `Request` object represents an incoming HTTP request. It stores query string, parameters, body, headers, method, and protocol information. By convention, the request object is named `req` (with the corresponding response named `res`).

Format

An [`R6::R6Class`] generator for `Request` objects.

See also

[Response]

Public fields

parameters

Named list of route parameters.

headers

Named list of request headers.

path

The request path.

method

HTTP method (e.g., `"GET"`, `"POST"`).

raw

The raw request object as received.

type

Content type (e.g., `"text/html"`, `"application/json"`).

body

Raw request body as a single string.

protocol

Protocol string (`"http"` or `"websocket"`).

Methods


Method attach()

Attach a parameter key-value to `parameters`.

Usage

Request$attach(key, value)

Arguments

key

Parameter name.

value

Parameter value.


Method getHeader()

Get the value of a request header.

Usage

Request$getHeader(key)

Arguments

key

Header name (case-insensitive).


Method setHeader()

Set or overwrite a request header.

Usage

Request$setHeader(key, value)

Arguments

key

Header name.

value

Header value.


Method addParameters()

Merge a named list of parameters into `parameters`.

Usage

Request$addParameters(named_list)

Arguments

named_list

Named list of key-value pairs.


Method new()

Parse fields from the raw request and populate the object.

Usage

Request$new(req)

Arguments

req

Raw request object.


Method clone()

The objects of this class are cloneable with this method.

Usage

Request$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.