RequestDelegate class

Utility which can read and write data via the network.

RequestDelegate instances accept a function for each http verb, making them wrappers for the actual http library that are suitable for dependency injection and tests.

Constructors

RequestDelegate.fake({ReadHandler? readHandler, WriteRequestHandler? postHandler, WriteRequestHandler? putHandler, WriteRequestHandler? patchHandler, WriteRequestHandler? deleteHandler, ResponseProcessor? responseProcessor})
Fake RequestDelegate which uses stubs to fake network requests. Omitting a value for some of the http verbs will cause this fake to throw an exception if those verbs are invoked, which helps with testing.
factory
RequestDelegate.live()
Live RequestDelegate which uses the http library to make real network requests.
const
factory

Properties

deleteHandler WriteRequestHandler
Method to execute DELETE requests.
final
hashCode int
The hash code for this object.
no setterinherited
patchHandler WriteRequestHandler
Method to execute PATCH requests.
final
postHandler WriteRequestHandler
Method to execute POST requests.
final
putHandler WriteRequestHandler
Method to execute PUT requests.
final
readHandler ReadHandler
Method to execute GET requests.
final
responseProcessor ResponseProcessor
Method which converts http.Response objects into ApiResult objects.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete(String url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<ApiResult>
Executes a DELETE request via deleteHandler.
get(String url, {required Map<String, String> headers}) Future<ApiResult>
Executes a GET request via readHandler.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch(String url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<ApiResult>
Executes a PATCH request via patchHandler.
post(String url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<ApiResult>
Executes a POST request via postHandler.
put(String url, {Map<String, String>? headers, Object? body, Encoding? encoding}) Future<ApiResult>
Executes a PUT request via putHandler.
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

processResponse(DateTime sentAt, Response resp) ApiResult
Unpacks an http.Response object into an ApiResult.