Skip to main content

HttpTransportManager

HTTP transport manager for working with a remote Duit server.

Implements TransportCapabilityDelegate and provides HTTP communication with the server for fetching UI layouts and executing server actions.

Constructor​

HttpTransportManager({
required String url,
String baseUrl = "",
Map<String, String> defaultHeaders = const {},
void Function(Request request)? requestInterceptor,
void Function(Object? error)? errorInterceptor,
Converter<Object?, String>? encoder,
Converter<Uint8List, Object?>? decoder,
String initialRequestMethod = "GET",
bool useSSEConn = false,
});

Parameters​

ParameterTypeDefaultDescription
urlString—URL for the initial request (required)
baseUrlString""Base URL for all HTTP requests
defaultHeadersMap<String, String>{}Headers added to every request
requestInterceptorFunction?nullInterceptor for modifying requests before sending
errorInterceptorFunction?nullHandler for HTTP request errors
encoderConverter?nullCustom encoder for request body
decoderConverter?nullCustom decoder for server response
initialRequestMethodString"GET"HTTP method for the initial request
useSSEConnboolfalseEnable SSE (Server-Sent Events) mode

Usage Examples​

Basic Usage​

final driver = XDriver.remote(
transportManager: HttpTransportManager(
url: '/api/layout',
baseUrl: 'https://api.example.com',
),
);

With Custom Headers and Interceptors​

final driver = XDriver.remote(
transportManager: HttpTransportManager(
url: '/api/layout',
baseUrl: 'https://api.example.com',
defaultHeaders: {
'Authorization': 'Bearer $token',
'X-Custom-Header': 'value',
},
requestInterceptor: (request) {
print('Sending request to: ${request.url}');
},
errorInterceptor: (error) {
print('HTTP Error: $error');
},
),
);

With Server-Sent Events (SSE)​

final driver = XDriver.remote(
transportManager: HttpTransportManager(
url: '/api/sse',
baseUrl: 'https://api.example.com',
useSSEConn: true,
),
);
tip

SSE mode allows the server to send UI updates in real-time through a persistent HTTP connection.