RestClient class
Abstract client that calls remove endpoints using HTTP/REST protocol.
Configuration parameters
base_route
: base route for remote URI- connection:
discovery_key
: (optional) a key to retrieve the connection fromIDiscovery
protocol
: connection protocol: http or httpshost
: host name or IP addressport
: port number- uri: resource URI or connection string with all parameters in it
- options:
References
- *:logger:*:*:1.0 (optional)
ILogger
components to pass log messages - *:counters:*:*:1.0 (optional)
ICounters
components to pass collected measurements - *:discovery:*:*:1.0 (optional)
IDiscovery
services to resolve connection
See RestService See CommandableHttpService
Example
class MyRestClient extends RestClient implements IMyClient {
...
Future<MyData> getData(String correlationId, String id) async {
var timing = instrument(correlationId, 'myclient.get_data');
try{
var result = await call('get', '/get_data' correlationId, { id: id }, null);
timing.endTiming();
return result;
} catch (err) {
timing.endTiming();
rethrow;
});
}
...
}
var client = MyRestClient();
client.configure(ConfigParams.fromTuples([
'connection.protocol', 'http',
'connection.host', 'localhost',
'connection.port', 8080
]));
var result = await client.getData('123', '1');
...
- Implementers
Constructors
Properties
- baseRoute ↔ String
-
The base route.
read / write
- client ↔ Client
-
The HTTP client.
read / write
- connectionResolver ↔ HttpConnectionResolver
-
The connection resolver.
read / write
- connectTimeout ↔ int
-
The connection timeout in milliseconds.
read / write
- counters ↔ CompositeCounters
-
The performance counters.
read / write
-
headers
↔ Map<
String, String> -
The default headers to be added to every request.
read / write
- logger ↔ CompositeLogger
-
The logger.
read / write
- options ↔ ConfigParams
-
The configuration options.
read / write
- retries ↔ int
-
The number of retries.
read / write
- timeout ↔ int
-
The invocation timeout in milliseconds.
read / write
- uri ↔ String
-
The remote service uri which is calculated on open.
read / write
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
addCorrelationId(
Map< String, String> params, String correlationId) → Map<String, String> - Adds a correlation id (correlation_id) to invocation parameter map. [...]
-
addFilterParams(
Map< String, String> params, FilterParams filter) → Map<String, String> - Adds filter parameters (with the same name as they defined) to invocation parameter map. [...]
-
addPagingParams(
Map< String, String> params, PagingParams paging) → Map<String, String> - Adds paging parameters (skip, take, total) to invocation parameter map. [...]
-
call(
String method, String route, String correlationId, Map< String, String> params, [ dynamic data ]) → Future - Calls a remote method via HTTP/REST protocol. [...]
-
close(
String correlationId) → Future - Closes component and frees used resources. [...]
-
configure(
ConfigParams config) → void - Configures component by passing configuration parameters. [...]
-
createRequestRoute(
String route) → String -
instrument(
String correlationId String name) → Timing - Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement. [...]
-
instrumentError(
String correlationId, String name, dynamic err, [ bool reerror = false ]) → void - Adds instrumentation to error handling. [...]
-
isOpen(
) → bool - Checks if the component is opened. Returns true if the component has been opened and false otherwise.
-
open(
String correlationId) → Future - Opens the component. [...]
-
setReferences(
IReferences references) → void - Sets references to dependent components. [...]
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited