BloomRpcClient class
High-level typed RPC client that executes BloomRpcContract endpoints over HTTP.
BloomRpcClient coordinates contract execution:
- Path Interpolation: Replaces
:paramswith checked, percent-encoded values. - Query & Body Handling: Routes input to query parameters on GETs and JSON bodies on POST/PUT/PATCH.
- Authentication: Injects Bearer tokens dynamically via authTokenProvider or statically via authToken.
- Structured Errors: Catches network failures and translates them into strongly typed BloomRpcHttpException, BloomRpcTransportException, or BloomRpcDecodeException instances.
- Cancellation & Timeout: Supports per-request cancellation tokens (BloomRpcCancelToken) and timeouts.
Example
final rpcClient = BloomRpcClient(
baseUrl: 'https://api.example.com/v1',
authTokenProvider: () => authStore.token.value,
timeout: Duration(seconds: 10),
);
// Execute typed contract with full output type inference
final Task task = await rpcClient.call(
getTaskContract,
null,
pathParams: {'id': 'task-123'},
);
Constructors
-
BloomRpcClient({BloomHttpClient? httpClient, String? baseUrl, Duration timeout = const Duration(seconds: 15), Map<
String, String> ? defaultHeaders, String? authToken, String? authTokenProvider()?}) -
Creates a BloomRpcClient configured with
baseUrl,timeout, and authentication options.
Properties
- authToken ↔ String?
-
Static Bearer authentication token.
getter/setter pair
- authTokenProvider ↔ String? Function()?
-
Dynamic Bearer authentication token provider callback.
getter/setter pair
- baseUrl → String?
-
Base URL prefix for relative contract paths.
final
-
defaultHeaders
→ Map<
String, String> -
Default headers attached to outgoing RPC requests.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- httpClient → BloomHttpClient
-
The underlying HTTP client transport.
final
-
requestInterceptors
→ List<
RequestInterceptor> -
Ordered list of request interceptors executed prior to dispatching requests.
no setter
-
responseInterceptors
→ List<
ResponseInterceptor> -
Ordered list of response interceptors executed upon receiving responses.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- timeout → Duration
-
Default timeout applied to RPC calls.
final
Methods
-
call<
TInput, TOutput> (BloomRpcContract< TInput, TOutput> contract, TInput input, {Map<String, dynamic> ? pathParams, Map<String, dynamic> ? queryParameters, Map<String, String> ? headers, Duration? timeout, BloomRpcCancelToken? cancelToken}) → Future<TOutput> -
Executes a typed
contractwithinput, returning the decodedTOutput. -
close(
) → void - Closes the underlying HTTP client transport.
-
invoke<
TInput, TOutput> (BloomRpcContract< TInput, TOutput> contract, TInput input, {Map<String, dynamic> ? pathParams, Map<String, dynamic> ? queryParameters, Map<String, String> ? headers, Duration? timeout, BloomRpcCancelToken? cancelToken}) → Future<TOutput> - Alias for call.
-
mutation<
TInput, TOutput> (BloomRpcContract< TInput, TOutput> contract, {List<List> invalidateKeys = const [], List<BloomRpcContract> invalidateContracts = const [], Map<String, dynamic> ? pathParamsBuilder(TInput input)?, Map<String, dynamic> ? defaultPathParams, Map<String, dynamic> ? queryParameters, Map<String, String> ? headers, Duration? timeout, List? optimisticKey, OptimisticUpdater<TOutput, TInput> ? optimisticData, OnMutateCallback<TInput> ? onMutate, OnSuccessCallback<TOutput, TInput> ? onSuccess, OnErrorCallback<TInput> ? onError, OnSettledCallback<TOutput, TInput> ? onSettled}) → BloomMutation<TOutput, TInput> -
Creates a declarative BloomMutation bound to this client and
contract. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
query<
TInput, TOutput> (BloomRpcContract< TInput, TOutput> contract, TInput input, {Map<String, dynamic> ? pathParams, Map<String, dynamic> ? queryParameters, Map<String, String> ? headers, Duration staleTime = const Duration(minutes: 5), Duration cacheTime = const Duration(minutes: 30), bool enabled = true, TOutput? initialData, List? customKey, Duration? timeout}) → BloomQuery<TOutput> -
Creates a reactive BloomQuery bound to this client and
contract. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited