RestInterceptor class abstract interface

Defines the interceptor interface used to customize and extend the behavior of REST client request execution within the Jetleaf framework.

A RestInterceptor provides lifecycle hooks that are invoked at different stages of an HTTP request:

  1. Before Execution — modify or validate the RestHttpRequest
  2. Around Execution — perform side effects or wrapping logic
  3. After Execution — process or inspect the RestHttpResponse

This mechanism allows cross-cutting concerns such as:

  • Request/response logging
  • Metrics and performance tracking
  • Retry and circuit breaker logic
  • Authentication and header injection
  • Response transformation

Example

class LoggingInterceptor implements RestInterceptor {
  @override
  Future<void> beforeExecution(RestHttpRequest request) async {
    print("[Request] ${request.getMethod()} to ${request.uri}");
  }

  @override
  Future<void> aroundExecution(RestHttpRequest request) async {
    // Could measure execution time or wrap request in retry logic
  }

  @override
  Future<void> afterExecution(RestHttpResponse response) async {
    print("[Response] Status: ${response.getStatus()}");
  }
}

Integration

Interceptors are typically registered using a RestClient:

final rest = MyRestClient()
  .withInterceptors([LoggingInterceptor(), AuthInterceptor()]);

Each interceptor executes sequentially in the order they are registered.

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

afterExecution(RestHttpResponse response) → Future<void>
Called after the RestHttpResponse has been received.
aroundExecution(RestHttpRequest request) → Future<void>
Called around the execution phase of a request.
beforeExecution(RestHttpRequest request) → Future<void>
Defines the interceptor interface used to customize and extend the behavior of REST client request execution within the Jetleaf framework.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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