APIResponse<T> class
Represents an API response.
- Inheritance
-
- Object
- APIMetricSet
- APIResponse
- Mixed-in types
Constructors
-
APIResponse(APIResponseStatus status, {Map<
String, dynamic> ? headers, T? payload, Object? payloadDynamic, Object? payloadMimeType, Etag? payloadETag, CacheControl? cacheControl, String? payloadFileExtension, Duration? keepAliveTimeout, int? keepAliveMaxRequests, dynamic error, StackTrace? stackTrace, Map<String, APIMetric> ? metrics}) - Constructs an APIResponse.
-
APIResponse.badRequest({Map<
String, dynamic> ? headers, T? payload, Object? payloadDynamic, Object? mimeType, Object? error, Map<String, APIMetric> ? metrics}) -
Creates a response of status
BAD_REQUEST.factory -
APIResponse.error({Map<
String, dynamic> ? headers, dynamic error, StackTrace? stackTrace, Map<String, APIMetric> ? metrics}) -
Creates an error response.
factory
- APIResponse.from(dynamic o)
-
Creates a response based into
ovalue.factory -
APIResponse.notFound({Map<
String, dynamic> ? headers, T? payload, Object? payloadDynamic, Object? mimeType, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Map<String, APIMetric> ? metrics}) -
Creates a response of status
NOT_FOUND.factory -
APIResponse.notModified({Map<
String, dynamic> ? headers, T? payload, Object? payloadDynamic, Object? mimeType, Etag? eTag, CacheControl? cacheControl, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Map<String, APIMetric> ? metrics}) -
Creates a response of status
NOT_FOUND.factory -
APIResponse.ok(T? payload, {Object? payloadDynamic, Etag? payloadETag, CacheControl? cacheControl, Map<
String, dynamic> ? headers, Object? mimeType, String? fileExtension, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Map<String, APIMetric> ? metrics}) -
Creates a response of status
OK.factory -
APIResponse.redirect(Uri location, {Map<
String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) -
Creates a response of status
REDIRECT.factory -
APIResponse.redirecy(Uri location, {Map<
String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) -
factory
-
Creates a response of status
UNAUTHORIZED.factory
Properties
- apiRequest → APIRequest?
-
Returns the APIRequest of this response.
no setter
- authenticationRealm → String?
-
The real of the required
Authentication.no setter - authenticationType → String?
-
The type of the required
Authentication.no setter - cacheControl ↔ CacheControl?
-
The response CacheControl.
getter/setter pair
- continuation ↔ String?
-
The continuation token of this response (headerXContinuation): the
route has more work to do, and should be called again with it (as the
continuationparameter).nullwhen done.getter/setter pair - error → dynamic
-
The response error.
final
- hasCORS → bool
-
Returns
trueif this response hasCORS(Cross-origin Resource Sharing) headers set.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasMetrics → bool
-
Returns
trueif any metric is set. See metrics.no setterinherited - hasPayload → bool
-
Returns
trueif payload is notnull.no setterinherited -
headers
→ Map<
String, dynamic> -
The response headers.
final
- isBadRequest → bool
-
Returns
trueif status is a APIResponseStatus.BAD_REQUEST.no setter - isError → bool
-
Returns
trueif status is a APIResponseStatus.ERROR.no setter - isNotFound → bool
-
Returns
trueif status is a APIResponseStatus.NOT_FOUND.no setter - isNotModified → bool
-
Returns
trueif status is a APIResponseStatus.NOT_MODIFIED.no setter - isNotOK → bool
-
Alias to ![isNotOK].
no setter
- isNotValid → bool
-
Alias to ![isValid].
no setter
- isOK → bool
-
Returns
trueif status is a APIResponseStatus.OK.no setter -
Returns
trueif status is a APIResponseStatus.UNAUTHORIZED.no setter - isValid → bool
-
Returns
trueif status is a APIResponseStatus.OK or a APIResponseStatus.NOT_FOUND.no setter - keepAliveMaxRequests ↔ int
-
The
Keep-Alivemaximum number of requests. Default:1000getter/setter pair - keepAliveTimeout ↔ Duration
-
The
Keep-Alivetimeout. Default:10sgetter/setter pair -
metrics
→ Map<
String, APIMetric> -
Returns the current metrics.
no setterinherited
- payload → T?
-
The response payload/body/
final
- payloadETag ↔ Etag?
-
The Etag of the payload.
getter/setter pair
- payloadFileExtension ↔ String?
-
The payload usual file name extension.
getter/setter pairoverride-getter
- payloadLength → int
-
Returns the payload length.
no setterinherited
- payloadMimeType ↔ MimeType?
-
The payload/body MIME Type.
getter/setter pairoverride-getter
- payloadZone → Zone?
-
The Zone where a Future payload was created: the error Zone of
the APIRoot.call. An error of that Future is only delivered to the
listeners registered inside it (errors don't cross error Zones), so
listen to it with runInPayloadZone.
no setter
- requiresAuthentication → bool
-
If
truethis response should requireAuthentication. See authenticationType and authenticationRealm.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace?
-
final
- status → APIResponseStatus
-
The response status.
final
Methods
-
asBadRequest(
{T? payload, Object? payloadDynamic, Map< String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
BAD_REQUESTresponse. -
asError(
{Map< String, dynamic> ? headers, dynamic error, StackTrace? stackTrace, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
ERRORresponse. -
asNotFound(
{T? payload, Object? payloadDynamic, Map< String, dynamic> ? headers, Object? mimeType, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to a
NOT_FOUNDresponse. -
asNotModified(
{T? payload, Object? payloadDynamic, Map< String, dynamic> ? headers, Object? mimeType, Etag? eTag, CacheControl? cacheControl, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to a
NOT_MODIFIEDresponse. -
asOk(
{T? payload, Object? payloadDynamic, Map< String, dynamic> ? headers, Object? mimeType, String? fileExtension, Etag? eTag, CacheControl? cacheControl, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
OKresponse. -
asRedirect(
{Uri? location, Map< String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
REDIRECTresponse. -
asRedirecy(
{Uri? location, Map< String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
UNAUTHORIZEDresponse. -
cast<
E> ({E? payload, Object? error}) → APIResponse< E> -
Copy this response casting the
payloadtoE. -
copy(
{APIResponseStatus? status, T? payload, Object? payloadDynamic, bool nullPayload = false, Etag? payloadETag, String? payloadFileExtension, CacheControl? cacheControl, Map< String, dynamic> ? headers, Object? mimeType, Duration? keepAliveTimeout, int? keepAliveMaxRequests, Object? error, StackTrace? stackTrace, Map<String, APIMetric> ? metrics}) → APIResponse<T> - Copy this response.
-
dispose(
) → void -
override
-
disposeAsync(
) → Future< void> -
Asynchronous call to dispose.
inherited
-
getHeader(
String headerKey, {String? def}) → String? -
getMetric(
String name) → APIMetric? -
Returns a metric.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
payloadAs<
E> () → E -
Returns payload cast to
E. -
requireAuthentication(
{bool require = true, String type = 'Basic', String realm = 'API'}) → APIResponse< T> - Defines that this response requires authentication.
-
runInPayloadZone<
R> (R f()) → R -
Runs
fin the payloadZone (or the current Zone if not defined). Use it to listen to a Future payload, so its error is received. -
setCORS(
APIRequest request, {bool allowCredentials = true, List< String> ? allowMethods, List<String> ? allowHeaders, List<String> ? exposeHeaders}) → void -
Sets the
CORS(Cross-origin Resource Sharing) headers of this response. -
setMetric(
String name, {Duration? duration, String? description, int? n}) → APIMetric -
Set a metric.
inherited
-
startMetric(
String name, {String? description}) → DateTime -
Starts a metric chronometer.
inherited
-
stopAllMetrics(
{DateTime? now}) → void -
inherited
-
stopMetric(
String name, {DateTime? now}) → Duration? -
Stops a metric previously started and adds it to metrics.
See startMetric.
inherited
-
toInfos(
) → String - Response infos.
-
toString(
) → String -
Returns the payload or the status as String.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- exposeHeaders → String
-
final
- headerXAccessToken → String
-
final
- headerXAccessTokenExpiration → String
-
final
- headerXContinuation → String
-
The header with the continuation token of a route with more work to do
(another page, a cursor...). See continuation.
final
- typeInfo → TypeInfo
-
final