SparkRequest class

Request context for page loaders.

Provides access to the underlying Shelf request along with parsed path parameters, query parameters, and other utilities.

Usage

@override
Future<PageResponse<User>> loader(PageRequest request) async {
  // Path parameters from route pattern
  final userId = request.pathParamInt('id');

  // Query parameters from URL
  final page = request.queryParamInt('page', 1);
  final sortBy = request.queryParam('sort', 'name');

  // Headers
  final authHeader = request.header('authorization');

  // Cookies
  final sessionId = request.cookie('session_id');

  // Access context added by middleware
  final user = request.context['user'] as User?;

  // ...
}

Constructors

SparkRequest({required Request shelfRequest, required Map<String, String> pathParams})
Creates a page request wrapping a Shelf request.
const

Properties

context → Map<String, Object>
Request context for middleware-added data.
no setter
cookies → Map<String, String>
Gets all cookies from the request.
no setter
hashCode → int
The hash code for this object.
no setterinherited
headers → Map<String, String>
HTTP headers from the request.
no setter
mediaType → MediaType?
Helper to get generic MediaType.
no setter
method → String
The HTTP method (GET, POST, etc.).
no setter
multipart → Stream<MultipartPart>
PARSES the request body as a multipart stream.
no setter
path → String
The URL path.
no setter
pathParams → Map<String, String>
Path parameters extracted from the URL pattern.
final
queryParams → Map<String, String>
Query parameters from the URL.
no setter
queryParamsAll → Map<String, List<String>>
All query parameters including duplicates.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shelfRequest → Request
The underlying Shelf request.
final
uri → Uri
The full requested URI.
no setter

Methods

Gets a specific cookie value by name.
get<T>() → T
Gets a value from the request context provided via middleware.
Gets a header value by name (case-insensitive).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pathParam(String name, [String defaultValue = '']) → String
Gets a path parameter by name.
pathParamInt(String name, [int defaultValue = 0]) → int
Gets a path parameter as an integer.
queryParam(String name, [String defaultValue = '']) → String
Gets a query parameter by name.
queryParamAll(String name) → List<String>
Gets all values for a query parameter.
queryParamBool(String name, [bool defaultValue = false]) → bool
Gets a query parameter as a boolean.
queryParamDouble(String name, [double defaultValue = 0.0]) → double
Gets a query parameter as a double.
queryParamInt(String name, [int defaultValue = 0]) → int
Gets a query parameter as an integer.
readBody() → Future<String>
Reads the request body as a string.
toString() → String
A string representation of this object.
inherited
withContext(Map<String, Object> additionalContext) → SparkRequest
Creates a new SparkRequest with additional context.
withPathParams(Map<String, String> newPathParams) → SparkRequest
Creates a new SparkRequest with modified path parameters.

Operators

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