Skip to content

Latest commit

 

History

History
48 lines (35 loc) · 1.36 KB

interceptors.md

File metadata and controls

48 lines (35 loc) · 1.36 KB

Interceptors

Request

Implement RequestInterceptor class or define function with following signature FutureOr<Request> RequestInterceptorFunc(Request request)

Request interceptor are called just before sending request

final chopper = ChopperClient(
   interceptors: [
     (request) async => request.copyWith(body: {}),
   ]
);

Response

Implement ResponseInterceptor class or define function with following signature FutureOr<Response> ResponseInterceptorFunc(Response response)

{% hint style="info" %} Called after successful or failed request {% endhint %}

final chopper = ChopperClient(
   interceptors: [
     (Response response) async => response.replace(body: {}),
   ]
);

Builtins

Both the CurlInterceptor and HttpLoggingInterceptor use the dart logging package. In order to see logging in console the logging package also needs to be added to your project and configured.

For example:

Logger.root.level = Level.ALL; // defaults to Level.INFO
Logger.root.onRecord.listen((record) {
  print('${record.level.name}: ${record.time}: ${record.message}');
});