CommandableHttpService

Abstract service that receives remote calls via HTTP/REST protocol to operations automatically generated for commands defined in ICommandable components.

Implements: RestService

See also RestService, CommandableHttpClient

Description

The CommandableHttpService class allows you to create services that receive remote calls via the HTTP/REST protocol to operations automatically generated for commands defined in ICommandable components.

Important points

  • Each command is exposed as POST operation that receives all parameters in the body object.
  • Commandable services require only three 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
  • *:traces:*:*:1.0 - (optional) ITracer components to record traces
  • *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve connection

Constructors

Creates a new instance of the service.

CommandableHttpService(base_route: str)

  • base_route: str - a service base route.

Fields

_connection_resolver

Create connection resolver.

_connection_resolver: ConnectionResolver = ConnectionResolver()

_command_set

Set of commands.

_command_set: CommandSet

_swagger_auto

Boolean variable that defines whether the configuration of Swagger is autogenerated or not.

_swagger_auto: bool = True

_base_route

Base route for a remote URI

_base_route: str

Instance methods

configure

Configures a component by passing configuration parameters.

configure(config: ConfigParams)

  • config: ConfigParams - configuration parameters to be set.

register

Registers all service routes in the HTTP endpoint.

register()

Examples

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")
# ...

See also