Request class
An HTTP request to be processed by a Relic Server application.
The Request object provides access to all information about an incoming HTTP request, including the method, URL, headers, query parameters, and body.
Usage Examples
// Basic request handling
router.get('/users/:id', (req) {
// Access path parameters
final id = req.pathParameters[#id];
// Access HTTP method
print(req.method); // Method.get
// Access query parameters
final sort = req.url.queryParameters['sort'];
final filter = req.url.queryParameters['filter'];
// Multiple values for same parameter
// URL: /tags?tag=dart&tag=server
final tags = req.url.queryParametersAll['tag'];
// tags = ['dart', 'server']
// Access headers
final userAgent = req.headers.userAgent;
return Response.ok(
body: Body.fromString('User request'),
);
});
// Reading request body
router.post('/api/data', (req) async {
// Check if body exists
if (req.isEmpty) {
return Response.badRequest();
}
// Read as string
final bodyText = await req.readAsString();
// Parse JSON
final data = jsonDecode(bodyText);
return Response.ok();
});
- Inheritance
- Available extensions
Properties
- body ↔ Body
-
The streaming body of the message.
getter/setter pairinherited
- connectionInfo → ConnectionInfo
-
Information about the IP connection carrying the request.
final
- encoding → Encoding?
-
Returns the encoding specified in the Body-Type (Content-Type header), or null if not specified.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- headers → Headers
-
The HTTP headers associated with this message.
finalinherited
- isEmpty → bool
-
Determines if the body is empty by checking the content length.
no setterinherited
- matchedPath → NormalizedPath
-
Available on Request, provided by the RoutingRequestEx extension
The portion of the request path that was matched by the route.no setter - method → Method
-
The HTTP request method, such as "GET" or "POST".
final
- mimeType → MimeType?
-
Returns the MIME type from the Body-Type (Content-Type header), if available.
no setterinherited
- pathParameters → PathParameters
-
Available on Request, provided by the PathParametersRequestEx extension
Typed path parameters extracted from the matched route.no setter - protocolVersion → String
-
The HTTP protocol version used in the request, either "1.0" or "1.1".
final
- queryParameters → QueryParameters
-
Available on Request, provided by the QueryParametersRequestEx extension
Typed query parameters extracted from the request URL.no setter -
rawPathParameters
→ Map<
Symbol, String> -
Available on Request, provided by the RoutingRequestEx extension
Raw path parameters extracted from the matched route.no setter - remainingPath → NormalizedPath
-
Available on Request, provided by the RoutingRequestEx extension
The portion of the request path that was not consumed by the matched route.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- url → Uri
-
The original Uri for the request.
final
Methods
-
copyWith(
{Headers? headers, Body? body}) → Request -
Creates a new Request by copying existing values and applying specified
changes.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
) → Stream< Uint8List> -
Reads the body as a stream of bytes. Can only be called once.
inherited
-
readAsString(
[Encoding? encoding]) → Future< String> -
Reads the body as a string, decoding it using the specified or detected encoding.
Defaults to utf8 if no encoding is provided or detected.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited