catcher_core library
Catcher — Resilient HTTP/WebSocket client for Flutter
Backed by Rust core via dart:ffi.
Quick Start
import 'package:catcher_core/catcher_core.dart';
void main() async {
// HTTP client
final client = CatcherHttpClient(HttpClientConfig(
baseUrl: 'https://api.example.com',
retry: RetryConfig(maxAttempts: 3),
pool: PoolConfig(keepAlive: true),
));
final resp = await client.get('/channels');
print('Status: ${resp.status}, Body: ${resp.bodyAsString}');
client.dispose();
// WebSocket client
final ws = CatcherWsClient(WsClientConfig(
urls: ['wss://echo.example.com'],
reconnect: WsReconnectConfig(initialDelayMs: 1000),
));
ws.events.listen((event) {
if (event is WsMessageEvent) {
print('Received: ${event.text}');
}
});
ws.sendText('hello');
await Future.delayed(Duration(seconds: 5));
ws.dispose();
}
Classes
- CatcherHttpClient
- Dart wrapper around the Rust catcher HTTP client via C ABI.
- CatcherSseClient
- Dart wrapper around the Rust SSE client via C ABI.
- CatcherWsClient
- Dart wrapper around the Rust catcher WebSocket client via C ABI.
- CircuitBreakerConfig
- DnsConfig
- DNS configuration
- HttpClientConfig
- HttpResponse
- NetworkQualityResult
- Network quality evaluation result.
- PoolConfig
- Connection pool configuration (matches Rust PoolConfig)
- ProxyAuth
- Proxy authentication
- ProxyConfig
- Proxy configuration
- RedirectConfig
- Redirect configuration
- RetryConfig
- SseClientConfig
- SseCloseEvent
- The SSE connection has been closed.
- SseDataEvent
- A data line was received from the SSE stream.
- SseErrorEvent
- An error occurred on the SSE connection.
- SseEvent
- Base class for SSE events received from the Rust SSE client.
- SseOpenEvent
- The SSE connection has been established (or re-established after reconnect).
- SseReconnectConfig
- StreamChunkEvent
- Received a data chunk (binary).
- StreamDoneEvent
- Stream completed successfully.
- StreamErrorEvent
- Stream encountered an error.
- StreamEvent
- Base class for streaming download events.
- StreamHeadersEvent
- Received response headers.
- TlsConfig
- TLS configuration
- WsClientConfig
- WsConnectedEvent
- WsDisconnectedEvent
- WsErrorEvent
- WsEvent
- WsHeartbeatConfig
- WsHeartbeatRttEvent
- WsMessageEvent
- WsReconnectConfig
- WsReconnectingEvent
Enums
Functions
-
evaluateQuality(
String host) → Future< NetworkQualityResult> - Evaluate network quality to the given host.
-
loadCatcherLibrary(
) → DynamicLibrary - Load the catcher native library.
-
pack(
dynamic value) → Uint8List - Pack a Dart value into msgpack binary.
-
qualityHistory(
) → String - Query the persistent quality sliding window history. Returns a JSON string with rtt_samples and current_level.
-
unpack(
Uint8List data) → dynamic - Unpack msgpack binary into a Dart value (parsed from JSON).
Exceptions / Errors
- CatcherHttpError
- Error thrown when the Rust HTTP client returns an error
- CatcherWsError
- Error thrown when the Rust WS client returns an error