Skip to content

Request Context

The RequestContext is a class that holds the request information and provides a way to interact with the request.

Using the RequestContext ensures that the information is consistent and that the request is processed correctly.

Properties

The RequestContext class has the following properties:

PropertyDescription
requestThe Request object that holds the request information.
providersA map of Providers that can be used to inject dependencies into the route handler.
headersA map of headers that were sent in the request.
paramsA map of path parameters that were sent in the request.
queryA map of query parameters that were sent in the request.
bodyThe body of the request.
pathThe path of the request that triggered the handler
resUtility class to interact with the response headers and statusCode.

WARNING

The statusCode value must be between 100 and 999.

Methods

The RequestContext class has the following methods:

MethodDescription
useReturns the Provider of the requested type - e.g. use<TestProvider>()
canUseChecks if the Provider of the requested type is available - e.g. canUse<TestProvider>()
statReturns the Metadata value of the requested name - e.g. stat('Metadata')
canStatChecks if the requested Metadata is available in the context - e.g. canStat('Metadata')
streamStarts a stream response - e.g. stream()

Built with 💙 and Dart 🎯 | One of the 🐤 of Avesbox