RequestContext class

Provides access to the current HTTP request within a request processing zone.

This class enables services and controllers to access the current request without having to pass it as a parameter through the call chain.

Key features:

  • Zone-based request storage and retrieval
  • Authentication shortcuts
  • Per-request custom data storage
  • Request profiling and timing
  • Automatic cleanup of request-scoped data

Constructors

RequestContext()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

acceptLanguage String?
Get the Accept-Language header
no setter
allData Map<String, dynamic>
Get all custom data for the current request
no setter
auth → Auth
This is a shorthand for RequestContext.request.auth.
no setter
authorization String?
Get the Authorization header
no setter
clientIp String?
Get the client IP address
no setter
contentType String?
Get the Content-Type header
no setter
hasRequest bool
Check if a request context is currently available
no setter
isAuthenticated bool
Check if the current request is authenticated
no setter
request Request
Use this to access the current request in the zone.
no setter
requestId String
Get the current request ID (useful for logging/tracing)
no setter
userAgent String?
Get the User-Agent string
no setter
userId → dynamic
Get the current user ID if authenticated
no setter

Static Methods

clear() → void
Clear all custom data for the current request
get<T>(String key) → T?
Retrieve custom data from the current request
has(String key) bool
Check if custom data exists for the current request
remove(String key) → void
Remove custom data from the current request
run<R>(Request request, R body()) → R
Run anything inside this request context.
set(String key, dynamic value) → void
Store custom data for the current request