Context class

The context for handling HTTP requests and responses.

Context provides access to:

  • Request data via req (including path params, query params, body)
  • Response via res
  • Arbitrary context data via get and set
Available extensions

Constructors

Context(HttpRequest req, HttpResponse res, [Map<String, String>? params, String? methodOverride])

Properties

deadline → DateTime?

Available on Context, provided by the TimeoutContextExtension extension

Gets the deadline for the current request.
no setter
hashCode → int
The hash code for this object.
no setterinherited
ifMatch → List<String>

Available on Context, provided by the ETagContextExtension extension

Gets the If-Match header values from the request.
no setter
ifNoneMatch → List<String>

Available on Context, provided by the ETagContextExtension extension

Gets the If-None-Match header values from the request.
no setter
isExpired → bool

Available on Context, provided by the TimeoutContextExtension extension

Checks if the request has exceeded its deadline.
no setter
isValid → bool

Available on Context, provided by the ValidationContextExtension extension

Whether the request passed validation.
no setter
locale → String

Available on Context, provided by the I18nContextExtension extension

Gets the current locale.
no setter
log → Log
Logger for this request context.
no setter
remainingTime → Duration?

Available on Context, provided by the TimeoutContextExtension extension

Gets the remaining time until deadline.
no setter
req → Req
The HTTP request.
no setter
requestId → String

Available on Context, provided by the RequestIdContextExtension extension

Gets the request ID for the current request.
no setter
requestIdOrNull → String?

Available on Context, provided by the RequestIdContextExtension extension

Gets the request ID or null if not available.
no setter
res → Res
The HTTP response.
no setter
response → MockHttpResponse

Available on Context, provided by the TestContextExtension extension

Returns the MockHttpResponse for assertions.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
session → SessionData

Available on Context, provided by the SessionContextExtension extension

Gets the current session.
no setter
sessionOrNull → SessionData?

Available on Context, provided by the SessionContextExtension extension

Gets the current session or null if not available.
no setter
validated → Map<String, Map<String, dynamic>>

Available on Context, provided by the ValidationContextExtension extension

Gets validated data by source (body, query, params).
no setter
validatedBody → Map<String, dynamic>?

Available on Context, provided by the ValidationContextExtension extension

Gets validated body data.
no setter
validatedParams → Map<String, dynamic>?

Available on Context, provided by the ValidationContextExtension extension

Gets validated params data.
no setter
validatedQuery → Map<String, dynamic>?

Available on Context, provided by the ValidationContextExtension extension

Gets validated query data.
no setter
validationErrors → Map<String, List<ValidationError>>

Available on Context, provided by the ValidationContextExtension extension

Gets validation errors by source.
no setter

Methods

checkEtag(String etag) → Future<bool>

Available on Context, provided by the ETagContextExtension extension

Sets the ETag header and returns 304 if it matches the client's version.
destroySession() → void

Available on Context, provided by the SessionContextExtension extension

Destroys the current session.
etagMatches(String etag) → bool

Available on Context, provided by the ETagContextExtension extension

Checks if the given ETag matches the If-None-Match header.
get<T>(String key) → T?
Retrieves a value from the context.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
regenerateSession() → void

Available on Context, provided by the SessionContextExtension extension

Regenerates the session ID while preserving data.
set<T>(String key, T value) → void
Stores a value in the context.
setDeadline(DateTime deadline) → void

Available on Context, provided by the TimeoutContextExtension extension

Sets a deadline for the current request.
t(String key, [Map<String, dynamic>? params]) → String

Available on Context, provided by the I18nContextExtension extension

Translates a key with optional parameters.
toString() → String
A string representation of this object.
inherited

Operators

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