CommandableHttpClient class Null safety

Abstract client that calls commandable HTTP service.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as POST operation that receives all parameters in body object.

Configuration parameters

base_route: base route for remote URI

  • connection:
    • discovery_key: (optional) a key to retrieve the connection from IDiscovery
    • protocol: connection protocol: http or https
    • host: host name or IP address
    • port: port number
    • uri: resource URI or connection string with all parameters in it
  • options:
    • retries: number of retries (default: 3)
    • connect_timeout: connection timeout in milliseconds (default: 10 sec)
    • timeout: invocation timeout in milliseconds (default: 10 sec)

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

Example

class MyCommandableHttpClient extends CommandableHttpClient implements IMyClient {
   ...

   Future<MyData> getData(String? correlationId, String id) async {
       var result = await callCommand(
           "get_data",
           correlationId,
           { 'id': id });
      if (result == null) return null;
      return MyData.fromJson(json.decode(result));
    }
    ...
}

var client = MyCommandableHttpClient();
client.configure(ConfigParams.fromTuples([
    "connection.protocol", "http",
    "connection.host", "localhost",
    "connection.port", 8080
]));

var result = await client.getData("123", "1")
...
Inheritance

Constructors

CommandableHttpClient(String baseRoute)
Creates a new instance of the client.

Properties

baseRoute String?
The base route.
read / writeinherited
client ↔ Client?
The HTTP client.
read / writeinherited
connectionResolver HttpConnectionResolver
The connection resolver.
read / writeinherited
connectTimeout int
The connection timeout in milliseconds.
read / writeinherited
correlationIdLocation String
read / writeinherited
counters ↔ CompositeCounters
The performance counters.
read / writeinherited
hashCode int
The hash code for this object.
read-onlyinherited
headers Map<String, String>
The default headers to be added to every request.
read / writeinherited
logger ↔ CompositeLogger
The logger.
read / writeinherited
options ↔ ConfigParams
The configuration options.
read / writeinherited
retries int
The number of retries.
read / writeinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
timeout int
The invocation timeout in milliseconds.
read / writeinherited
tracer ↔ CompositeTracer
The tracer.
read / writeinherited
uri String?
The remote service uri which is calculated on open.
read / writeinherited

Methods

addCorrelationId(Map<String, String>? params, String? correlationId) Map<String, String>
Adds a correlation id (correlation_id) to invocation parameter map.
inherited
addFilterParams(Map<String, String>? params, FilterParams? filter) Map<String, String>
Adds filter parameters (with the same name as they defined) to invocation parameter map.
inherited
addPagingParams(Map<String, String>? params, PagingParams? paging) Map<String, String>
Adds paging parameters (skip, take, total) to invocation parameter map.
inherited
call(String method, String route, String? correlationId, Map<String, String> params, [dynamic data]) Future
Calls a remote method via HTTP/REST protocol.
inherited
callCommand(String name, String? correlationId, dynamic params) Future
Calls a remote method via HTTP commadable protocol. The call is made via POST operation and all parameters are sent in body object. The complete route to remote method is defined as baseRoute + "/" + name.
close(String? correlationId) Future
Closes component and frees used resources.
inherited
configure(ConfigParams config) → void
Configures component by passing configuration parameters.
inherited
createRequestRoute(String route) String
inherited
instrument(String? correlationId, String name) InstrumentTiming
Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement.
inherited
instrumentError(String? correlationId, String name, dynamic err, [bool? reerror = false]) → void
Adds instrumentation to error handling.
inherited
isOpen() bool
Checks if the component is opened. Returns true if the component has been opened and false otherwise.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
open(String? correlationId) Future
Opens the component.
inherited
setReferences(IReferences references) → void
Sets references to dependent components.
inherited
toString() String
A string representation of this object.
inherited

Operators

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