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, 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
o
value.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
- error → dynamic
-
The response error.
final
- hasCORS → bool
-
Returns
true
if this response hasCORS
(Cross-origin Resource Sharing) headers set.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hasMetrics → bool
-
Returns
true
if any metric is set. See metrics.no setterinherited - hasPayload → bool
-
Returns
true
if payload is notnull
.no setterinherited -
headers
→ Map<
String, dynamic> -
The response headers.
final
- isBadRequest → bool
-
Returns
true
if status is a APIResponseStatus.BAD_REQUEST.no setter - isError → bool
-
Returns
true
if status is a APIResponseStatus.ERROR.no setter - isNotFound → bool
-
Returns
true
if status is a APIResponseStatus.NOT_FOUND.no setter - isNotModified → bool
-
Returns
true
if 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
true
if status is a APIResponseStatus.OK.no setter -
Returns
true
if status is a APIResponseStatus.UNAUTHORIZED.no setter - isValid → bool
-
Returns
true
if status is a APIResponseStatus.OK or a APIResponseStatus.NOT_FOUND.no setter - keepAliveMaxRequests ↔ int
-
The
Keep-Alive
maximum number of requests. Default:1000
getter/setter pair - keepAliveTimeout ↔ Duration
-
The
Keep-Alive
timeout. Default:10s
getter/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
- requiresAuthentication → bool
-
If
true
this 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_REQUEST
response. -
asError(
{Map< String, dynamic> ? headers, dynamic error, StackTrace? stackTrace, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
ERROR
response. -
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_FOUND
response. -
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_MODIFIED
response. -
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
OK
response. -
asRedirect(
{Uri? location, Map< String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
REDIRECT
response. -
asRedirecy(
{Uri? location, Map< String, dynamic> ? headers, Object? mimeType, Map<String, APIMetric> ? metrics}) → APIResponse<T> -
Transform this response to an
UNAUTHORIZED
response. -
cast<
E> ({E? payload}) → APIResponse< E> -
Copy this response casting the
payload
toE
. -
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'}) → void - Defines that this response requires authentication.
-
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
- typeInfo → TypeInfo
-
final