Response class

Represents an HTTP response structure used in the Sirius backend framework.

This class encapsulates all the necessary details to construct an HTTP response, including response body, status code, headers, and advanced options like controlling middleware flow and passing contextual data.

Basic Example:

return Response.send({"message": "OK"});

Example with StatusCode and Headers:

return Response.send(
  {"error": "Not Found"},
  statusCode: HttpStatus.notFound,
  headers: {"X-Custom-Header": "value"},
);

Constructors

Response([Object? data, int statusCode = HttpStatus.ok, Map<String, String> headers = const {}, void overrideHeaders(HttpHeaders headers)?])
Constructs a Response instance.

Properties

data Object?
The response body data. Typically a Map, List, String, or null.
getter/setter pair
getContextData → dynamic
Retrieves the internal context data passed during processing.
no setter
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>
Custom headers to include in the HTTP response.
getter/setter pair
overrideHeaders ↔ void Function(HttpHeaders headers)?
A callback to override or manipulate low-level response headers.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setContextData ← dynamic
Sets extra internal context data to this response.
no getter
statusCode int
The HTTP status code of the response. Defaults to HttpStatus.ok (200).
getter/setter pair

Methods

addHeader(String key, String value) → void
Adds a custom header to the response.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

send(Object? data, {int statusCode = HttpStatus.ok, Map<String, String>? headers, void overrideHeaders(HttpHeaders headers)?}) Response
Creates a standard response with optional status code and headers.
sendFile(File file, {String? name, bool inline = false, Map<String, String>? headers, void overrideHeaders(HttpHeaders headers)?}) Response
Sends a file as an HTTP response.
sendJson(Object? data, {int statusCode = HttpStatus.ok, Map<String, String>? headers, void overrideHeaders(HttpHeaders headers)?}) Response
Sends a JSON response with appropriate Content-Type header.