RecordingClient class final

A test ApiClient that records requests and returns canned responses.

Useful for verifying that generated API clients send the correct requests without making real HTTP calls.

final client = RecordingClient();
final api = MyApi(ApiConfig(client: client));

await api.getUser(userId: '123');

expect(client.lastRequest!.method, equals('GET'));
expect(client.lastRequest!.path, equals('/users/123'));
Implemented types

Constructors

RecordingClient({ApiResponse? nextResponse, ApiResponse onRequest(ApiRequest request)?})
Creates a recording client with an optional default response.

Properties

baseUrl → Uri
Base URL for all requests. Must not have a trailing slash.
no setteroverride
hashCode → int
The hash code for this object.
no setterinherited
lastRequest → ApiRequest?
The most recently sent request, or null if no requests have been sent.
no setter
nextResponse ↔ ApiResponse
The response to return for the next send call.
getter/setter pair
nextStreamedResponse ↔ StreamedApiResponse?
The streaming response to return for the next sendStreaming call.
getter/setter pair
onRequest ↔ ApiResponse Function(ApiRequest request)?
Optional callback to dynamically generate responses based on the request.
getter/setter pair
requests → List<ApiRequest>
All requests sent through this client, in order.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future<void>
Close/dispose underlying resources.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Resets the recorded requests.
send(ApiRequest request) → Future<ApiResponse>
Send a request and return a buffered response.
override
sendStreaming(ApiRequest request) → Future<StreamedApiResponse>
Send a request and return a streaming response.
override
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

sseResponse(List<String> jsonEvents, {int statusCode = 200, String doneSignal = '[DONE]'}) → StreamedApiResponse
Create a StreamedApiResponse that emits SSE events from JSON strings.