The Request is the object that represents the incoming HTTP request. It contains all the information about the request, such as the headers, the body, the URL, and the method. While the
response can be heavily modified, the request is read-only, with the exception of the headers.
Read-Only#
The request is read-only, meaning that you cannot modify the request body, URL, method, or any other property of the request. This is because the request is already sent by the client, and the server should respond to the request as it is.
Accessing the Request#
Via Context#
The Request object can be accessed through the request property in the context of the Lifecycle Components.
final request = context.request;
Via Binding#
The Request object can be accessed via the controller's endpoint by adding the ReadOnlyRequest
parameter to the endpoint method.
@Get()
Future<void> helloWorld(
ReadOnlyRequest request,
) async {
...
}
Client IP#
Every request exposes the client IP as request.ip. Use @Ip()
in endpoints or read request.ip from context.
By default this is the TCP remote address. When the app runs behind a trusted reverse proxy, configure
trustedProxy on your app so Revali resolves the IP from proxy headers (for example
X-Forwarded-For).
See Client IP for binding examples, TrustedProxy
options, and security notes.