Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpEndpoint

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:

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

References

A logger, counters, and a connection resolver can be referenced by passing the following references to the object's setReferences method:

  • logger: "*:logger:*:*:1.0";
  • counters: "*:counters:*:*:1.0";
  • discovery: "*:discovery:*:*:1.0" (for the connection resolver).

Examples

public MyMethod(_config: ConfigParams, _references: IReferences) {
    let endpoint = new HttpEndpoint();
    if (this._config)
        endpoint.configure(this._config);
    if (this._references)
        endpoint.setReferences(this._references);
    ...

    this._endpoint.open(correlationId, (err) => {
            this._opened = err == null;
            callback(err);
        });
    ...
}

Hierarchy

  • HttpEndpoint

Implements

  • IOpenable
  • IConfigurable
  • IReferenceable

Index

Methods

close

  • close(correlationId: string, callback?: function): void
  • Closes this endpoint and the REST server (service) that was opened earlier.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      (optional) the function to call once the closing process is complete. Will be called with an error if one is raised.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

  • configure(config: ConfigParams): void
  • Configures this HttpEndpoint using the given configuration parameters.

    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.
    see

    ConfigParams (in the PipServices "Commons" package)

    Parameters

    • config: ConfigParams

      configuration parameters, containing a "connection(s)" section.

    Returns void

isOpen

  • isOpen(): boolean

open

  • open(correlationId: string, callback?: function): void
  • 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

    • correlationId: string

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

    • Optional callback: function

      (optional) the function to call once the opening process is complete. Will be called with an error if one is raised.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

register

registerRoute

  • registerRoute(method: string, route: string, schema: Schema, action: function): void
  • Registers an action in this objects REST server (service) by the given method and route.

    Parameters

    • method: string

      the HTTP method of the route.

    • route: string

      the route to register in this object's REST server (service).

    • schema: Schema

      the schema to use for parameter validation.

    • action: function

      the action to perform at the given route.

        • (req: any, res: any): void
        • Parameters

          • req: any
          • res: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void
  • Sets references to this endpoint's logger, counters, and connection resolver.

    References:

    • logger: "*:logger:*:*:1.0"
    • counters: "*:counters:*:*:1.0"
    • discovery: "*:discovery:*:*:1.0" (for the connection resolver)
    see

    IReferences (in the PipServices "Commons" package)

    Parameters

    • references: IReferences

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

    Returns void

unregister

Generated using TypeDoc