pip_services3_rpc.clients.CommandableHttpClient module
pip_services3_rpc.clients.CommandableHttpClient
Commandable HTTP client implementation
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
- class pip_services3_rpc.clients.CommandableHttpClient.CommandableHttpClient(base_route: str)
Bases:
pip_services3_rpc.clients.RestClient.RestClient
,abc.ABC
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(s):
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(CommandableHttpClient, IMyClient): # ... def get_data(self, correlation_id, id): return self.call_command("get_data", correlation_id, MyData(id)) # ... client = MyCommandableHttpClient() client.configure(ConfigParams.from_tuples("connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080)) data = client.getData("123", "1") # ...
- call_command(name: str, correlation_id: Optional[str], params: Any) Any
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.
- Parameters
name – a name of the command to call.
correlation_id – (optional) transaction id to trace execution through call chain.
params – command parameters.
- Returns
result of the command.