InterceptedHttp class
Class to be used by the user as a replacement for 'http' with interceptor support.
It is a useful class if you want to centralize HTTP request calls since it creates and discards InterceptedClient instances after the request is done and that allows you to avoid handling your own Client instances.
Call build()
and pass list of interceptors as parameter.
Example:
InterceptedHttp http = InterceptedHttp.build(interceptors: [
LoggingInterceptor(),
]);
Then call the functions you want to, on the created http
object.
http.get(...);
http.post(...);
http.put(...);
http.delete(...);
http.head(...);
http.patch(...);
http.send(...);
http.read(...);
http.readBytes(...);
Constructors
-
InterceptedHttp.build({required List<
InterceptorContract> interceptors, Duration? requestTimeout, TimeoutCallback? onRequestTimeout, RetryPolicy? retryPolicy, Client? client}) -
Builds a new InterceptedHttp instance. It helps avoid creating and
managing your own
Client
instances.factory
Properties
- client ↔ Client?
-
Inner client that is wrapped for intercepting.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
-
interceptors
→ List<
InterceptorContract> -
List of interceptors that will be applied to the requests and responses.
final
- onRequestTimeout ↔ TimeoutCallback?
-
Request timeout handler
getter/setter pair
- requestTimeout → Duration?
-
Maximum duration of a request.
final
- retryPolicy → RetryPolicy?
-
A policy that defines whether a request or response should trigger a
retry. This is useful for implementing JWT token expiration
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
delete(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params, Object? body, Encoding? encoding}) → Future<Response> - Performs a DELETE request with a new Client instance and closes it after it has been used.
-
get(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params}) → Future<Response> - Performs a GET request with a new Client instance and closes it after it has been used.
-
head(
dynamic url, {Map< String, String> ? headers}) → Future<Response> - Performs a HEAD request with a new Client instance and closes it after it has been used.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patch(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params, Object? body, Encoding? encoding}) → Future<Response> - Performs a PATCH request with a new Client instance and closes it after it has been used.
-
post(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params, Object? body, Encoding? encoding}) → Future<Response> - Performs a POST request with a new Client instance and closes it after it has been used.
-
put(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params, Object? body, Encoding? encoding}) → Future<Response> - Performs a PUT request with a new Client instance and closes it after it has been used.
-
read(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params}) → Future<String> -
Executes
client.read
with a new Client instance and closes it after it has been used. -
readBytes(
dynamic url, {Map< String, String> ? headers, Map<String, dynamic> ? params}) → Future<Uint8List> -
Executes
client.readBytes
with a new Client instance and closes it after it has been used. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited