ApiScript class

Lifecycle hooks that run before the request is sent or after the response arrives — identical to Postman's Pre-request Script and Post-response Script tabs.

ApiScript(
  preRequest: ({required headers, required params, required body}) async {
    headers['X-Timestamp'] = DateTime.now().millisecondsSinceEpoch.toString();
  },
  postResponse: ({required statusCode, required responseBody, required headers}) async {
    if (statusCode == 401) {
      // handle token expiry
    }
  },
)

Constructors

ApiScript({Future<void> preRequest({required Map<String, dynamic> body, required Map<String, String> headers, required Map<String, String> params})?, Future<void> postResponse({required Map<String, String> headers, required dynamic responseBody, required int statusCode})?})
Creates an ApiScript with optional pre-request and post-response hooks.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
postResponse Future<void> Function({required Map<String, String> headers, required dynamic responseBody, required int statusCode})?
Called after the HTTP response is received.
final
preRequest Future<void> Function({required Map<String, dynamic> body, required Map<String, String> headers, required Map<String, String> params})?
Called before the HTTP request is sent.
final
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
toString() String
A string representation of this object.
inherited

Operators

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