RequestInterceptor class abstract interface

An interface for implementing request interceptors.

RequestInterceptors are called after Converter.convertRequest.

While RequestInterceptors can modify the body of requests, converting (encoding) the request body should be handled by Converters.

See built-in CurlInterceptor and HttpLoggingInterceptor for fully functional example implementations.

A short example for adding an authentication token to every request:

class MyRequestInterceptor implements ResponseInterceptor {
  @override
  FutureOr<Request> onRequest(Request request) {
    return applyHeader(request, 'auth_token', 'Bearer $token');
  }
}

(See applyHeader(request, name, value) and applyHeaders(request, headers).)

Implementers
Annotations
  • @immutable

Constructors

RequestInterceptor()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onRequest(Request request) FutureOr<Request>
toString() String
A string representation of this object.
inherited

Operators

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