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})
Initializes a new Context for the given request and container.

Properties

body → Map<String, dynamic>
Returns the body of the request.
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
Returns the total elapsed time since the request was created.
no setter
hashCode → int
The hash code for this object.
no setterinherited
params → Map<String, dynamic>
Returns the path parameters of the request.
no setter
queryParams → Map<String, dynamic>
Returns the query parameters of the request.
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
Returns the response object.
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
Immediately terminates the request with the given res.
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 content, {int status = 200}) → Response
Generates an HTML response.
json(dynamic data, {int status = 200}) → Response
Generates a JSON 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 location, {int status = 302}) → Response
Generates a redirect response.
resolve<T>({String? name}) → T
Resolves an instance of type T from the request container.
set(String key, dynamic value) → void
Sets a value in the request-scoped data storage.
text(String content, {int status = 200}) → Response
Generates a plain text response.
toString() → String
A string representation of this object.
inherited
validate(FormRequest request) → Future<Map<String, dynamic>>
Validates the request body against a FormRequest.
validateData(Map<String, String> rules, [Map<String, String>? messages]) → Future<Map<String, dynamic>>
Validates the request body against the given rules.

Operators

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