pip_services3_rpc.clients.RestClient module
pip_services3_rpc.client.RestClient
REST 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.RestClient.RestClient
Bases:
pip_services3_commons.run.IOpenable.IOpenable
,pip_services3_commons.config.IConfigurable.IConfigurable
,pip_services3_commons.refer.IReferenceable.IReferenceable
Abstract client that calls remove endpoints using HTTP/REST protocol.
- ### 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 MyRestClient(RestClient, IMyClient): def get_data(self, correlation_id, id): timing = self.instrument(correlationId, 'myclient.get_data') result = self._controller.get_data(correlationId, id) timing.end_timing() return result # ... client = MyRestClient() client.configure(ConfigParams.fromTuples("connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080)) data = client.getData("123", "1") # ...
- add_correlation_id(params: Optional[Any] = None, correlation_id: Optional[str] = None) Any
Adds a correlation id (correlation_id) to invocation parameter map.
- Parameters
params – invocation parameters.
correlation_id – (optional) a correlation id to be added.
- Returns
invocation parameters with added correlation id.
- close(correlation_id: Optional[str])
Closes component and frees used resources.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)
Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
- fix_route(route) str
- is_open() bool
Checks if the component is opened.
- Returns
true if the component has been opened and false otherwise.
- open(correlation_id: Optional[str])
Opens the component.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- set_references(references: pip_services3_commons.refer.IReferences.IReferences)
Sets references to dependent components.
- Parameters
references – references to locate the component dependencies.