HttpResultHandler class
A thin, opt-in adapter that wraps package:http calls in Result values.
Built for quick prototypes and small apps: zero ceremony, no interceptors, no transformers. For production HTTP clients, prefer the Dio integration (DioResultHandler) which exposes interceptors, file transfers, and richer error mapping.
final api = HttpResultHandler(
baseUrl: 'https://api.example.com',
defaultHeaders: const {'Accept': 'application/json'},
);
final user = await api.get<User>(
'/users/me',
parser: (json) => User.fromJson(json! as Map<String, dynamic>),
);
user.when(
success: print,
error: (f) => print('failed: ${f.message}'),
);
Constructors
Properties
- baseUrl → String
-
Prefix prepended to every relative path passed to the verb methods.
final
-
defaultHeaders
→ Map<
String, String> -
Headers applied to every request, merged with per-call headers.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeout → Duration
-
Per-request timeout. A timeout produces Failure.timeout.
final
Methods
-
close(
) → void - Closes the underlying HTTP client if this handler created it.
-
delete<
T> (String path, {Object? body, Map< String, String> ? headers, Map<String, dynamic> ? queryParameters, required JsonParser<T> parser}) → Future<Result< T> > -
Performs a
DELETE. -
get<
T> (String path, {Map< String, String> ? headers, Map<String, dynamic> ? queryParameters, required JsonParser<T> parser}) → Future<Result< T> > -
Performs a
GETand decodes the response body viaparser. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patch<
T> (String path, {Object? body, Map< String, String> ? headers, Map<String, dynamic> ? queryParameters, required JsonParser<T> parser}) → Future<Result< T> > -
Performs a
PATCHwith a JSON-encodedbody. -
post<
T> (String path, {Object? body, Map< String, String> ? headers, Map<String, dynamic> ? queryParameters, required JsonParser<T> parser}) → Future<Result< T> > -
Performs a
POSTwith a JSON-encodedbody. -
put<
T> (String path, {Object? body, Map< String, String> ? headers, Map<String, dynamic> ? queryParameters, required JsonParser<T> parser}) → Future<Result< T> > -
Performs a
PUTwith a JSON-encodedbody. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited