Context class

Encapsulates the state of a single HTTP request and its lifecycle.

The Context provides access to the Request data, a request-scoped dependency injection Container, and convenience methods for generating responses. It also tracks the request's execution time.

Constructors

Context(Request request, {required Container container})

Properties

body Map<String, dynamic>
no setter
container Container
The dependency injection container scoped specifically to this request.
final
db DatabaseExecutor
Retrieves the active DatabaseExecutor from the Container.
no setter
elapsed Duration
no setter
hashCode int
The hash code for this object.
no setterinherited
params Map<String, dynamic>
no setter
queryParams Map<String, dynamic>
no setter
queue Queue
Retrieves the Queue instance from the Container.
no setter
request Request
The incoming HTTP request data.
final
requestId String
A unique 8-character identifier for this request, used for log correlation.
final
response Response
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
session Session
Returns the user session, if SessionMiddleware is active.
no setter
storage Storage
Retrieves the default Storage driver from the Container.
no setter
wsHub WebSocketHub
Retrieves the global WebSocketHub from the Container.
no setter

Methods

abort(Response res) → void
dispose() Future<void>
Disposes of the request-scoped Container and cleans up temporary files.
download(String path, [String? filename]) Response
Forces a file download by setting the Content-Disposition header.
file(String path) Response
Serves a file from the local filesystem.
get<T>(String key) → T?
Retrieves a value from the request-scoped data storage.
html(String html, {int status = 200}) Response
json(dynamic data, {int status = 200}) Response
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paramInt(String key, [int? defaultValue]) int?
Helper to get a path parameter as an integer.
query<T extends Model>(ModelFactory<T> factory, {String? tableName}) ModelQuery<T>
Creates a type-safe ModelQuery for the given model type T.
queryBool(String key, [bool defaultValue = false]) bool
Helper to get a query parameter as a boolean.
queryDouble(String key, [double? defaultValue]) double?
Helper to get a query parameter as a double.
queryInt(String key, [int? defaultValue]) int?
Helper to get a query parameter as an integer.
redirect(String url, {int status = 302}) Response
resolve<T>({String? name}) → T
set(String key, dynamic value) → void
Sets a value in the request-scoped data storage.
text(String text, {int status = 200}) Response
toString() String
A string representation of this object.
inherited
validate(FormRequest request) Future<Map<String, dynamic>>
validateData(Map<String, String> rules, [Map<String, String>? messages]) Future<Map<String, dynamic>>

Operators

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