pip_services3_rpc.services.HttpEndpoint module

pip_services3_rpc.services.HttpEndpoint

Http endpoint 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.HttpEndpoint.HttpEndpoint

Bases: pip_services3_commons.run.IOpenable.IOpenable, pip_services3_commons.config.IConfigurable.IConfigurable, pip_services3_commons.refer.IReferenceable.IReferenceable

Used for creating HTTP endpoints. An endpoint is a URL, at which a given service can be accessed by a client.

### Configuration parameters ###

Parameters to pass to the configure() method for component configuration:

  • cors_headers - a comma-separated list of allowed CORS headers

  • cors_origins - a comma-separated list of allowed CORS origins

  • connection(s) - the connection resolver’s connections;
    • “connection.discovery_key” - the key to use for connection resolving in a discovery service;

    • “connection.protocol” - the connection’s protocol;

    • “connection.host” - the target host;

    • “connection.port” - the target port;

    • “connection.uri” - the target URI.

  • credential - the HTTPS credentials:
    • “credential.ssl_key_file” - the SSL private key in PEM

    • “credential.ssl_crt_file” - the SSL certificate in PEM

    • “credential.ssl_ca_file” - the certificate authorities (root cerfiticates) in PEM

### References ###
A logger, counters, and a connection resolver can be referenced by passing the following references to the object’s set_references() method:
  • *: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:

def my_method(_config, _references):
    endpoint = HttpEndpoint()
    if (_config)
        endpoint.configure(_config)
    if (_references)
        endpoint.setReferences(_references)
    # ...

    endpoint.open(correlationId)
    # ...
close(correlation_id: Optional[str])

Closes this endpoint and the REST server (service) that was opened earlier.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures this HttpEndpoint using the given configuration parameters. - connection(s) - the connection resolver’s connections;

  • “connection.discovery_key” - the key to use for connection resolving in a discovery service;

  • “connection.protocol” - the connection’s protocol;

  • “connection.host” - the target host;

  • “connection.port” - the target port;

  • “connection.uri” - the target URI.

Parameters

config – configuration parameters, containing a “connection(s)” section.

get_correlation_id() Optional[str]

Returns correlationId from request

Returns

Returns correlationId from request

get_param(param, default=None)
is_open() bool

Checks if the component is opened.

Returns

whether or not this endpoint is open with an actively listening REST server.

open(correlation_id: Optional[str])

Opens a connection using the parameters resolved by the referenced connection resolver and creates a REST server (service) using the set options and parameters.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

register(registration: <module 'pip_services3_rpc.services.IRegisterable' from '/pip_services3_rpc/services/IRegisterable.py'>)

Registers a registerable object for dynamic endpoint discovery.

Parameters

registration – the registration to add.

register_interceptor(route: str, action: Callable)

Registers a middleware action for the given route.

Parameters
  • route – the route to register in this object’s REST server (service).

  • action – the middleware action to perform at the given route.

register_route(method: str, route: str, schema: pip_services3_commons.validate.Schema.Schema, handler: Callable)

Registers an action in this objects REST server (service) by the given method and route.

Parameters
  • method – the HTTP method of the route.

  • route – the route to register in this object’s REST server (service).

  • schema – the schema to use for parameter validation.

  • handler – the action to perform at the given route.

register_route_with_auth(method: str, route: str, schema: pip_services3_commons.validate.Schema.Schema, authorize: Callable, action: Callable)

Registers an action with authorization in this objects REST server (service) by the given method and route.

Parameters
  • method – the HTTP method of the route.

  • route – the route to register in this object’s REST server (service).

  • schema – the schema to use for parameter validation.

  • authorize – the authorization interceptor

  • action – the action to perform at the given route.

set_references(references: pip_services3_commons.refer.IReferences.IReferences)

Sets references to this endpoint’s logger, counters, and connection resolver.

  • :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

Parameters

references – an IReferences object, containing references to a logger, counters, and a connection resolver.

unregister(registration: <module 'pip_services3_rpc.services.IRegisterable' from '/pip_services3_rpc/services/IRegisterable.py'>)

Unregisters a registerable object, so that it is no longer used in dynamic endpoint discovery.

Parameters

registration – the registration to remove.