pip_services3_rpc.services.CommandableHttpService module

pip_services3_rpc.services.CommandableHttpService

Commandable HTTP service implementation

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_rpc.services.CommandableHttpService.CommandableHttpService(base_route: str)

Bases: pip_services3_rpc.services.RestService.RestService

Abstract service that receives remove calls via HTTP/REST protocol to operations automatically generated for commands defined in ICommandable components. Each command is exposed as POST operation that receives all parameters in body object. Commandable services require only 3 lines of code to implement a robust external HTTP-based remote interface.

### Configuration parameters ###
  • base_route: base route for remote URI

  • dependencies:
    • endpoint: override for HTTP Endpoint dependency

    • controller: override for Controller dependency

  • 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

### 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

  • *:endpoint:http:*:1.0 (optional) HttpEndpoint <pip_services3_rpc.services.HttpEndpoint reference

Example:

class MyCommandableHttpService(CommandableHttpService):
    def __init__(self):
        super(MyCommandableHttpService, self).__init__()
        self._dependencyResolver.put("controller", Descriptor("mygroup","controller","*","*","1.0"))

    # ...

service = MyCommandableHttpService()
service.configure(ConfigParams.from_tuples("connection.protocol", "http",
                                          "connection.host", "localhost",
                                          "connection.port", 8080))
service.set_references(References.from_tuples(Descriptor("mygroup","controller","default","default","1.0"), controller))
service.open("123")
# ...
configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

register()

Registers all service routes in HTTP endpoint.