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

  • any
  • any
  • any

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.
      • "credential.ssl_key_file" - SSL private key in PEM
      • "credential.ssl_crt_file" - SSL certificate in PEM
      • "credential.ssl_ca_file" - Certificate authority (root certificate) in PEM
    see

    ConfigParams (in the PipServices "Commons" package)

    Parameters

    • config: ConfigParams

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

    Returns void

getCorrelationId

  • getCorrelationId(req: any): string
  • Returns correlationId from request

    Parameters

    • req: any

      http request

    Returns string

    Returns correlationId from request

getServer

  • getServer(): any
  • Gets an HTTP server instance.

    Returns any

    an HTTP server instance of null if endpoint is closed.

isOpen

  • isOpen(): boolean
  • Returns boolean

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

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

  • Registers a registerable object for dynamic endpoint discovery.

    see

    IRegisterable

    Parameters

    Returns void

registerInterceptor

  • registerInterceptor(route: string, action: function): void
  • Registers a middleware action for the given route.

    Parameters

    • route: string

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

    • action: function

      the middleware action to perform at the given route.

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

          • req: any
          • res: any
          • next: function
              • (): void
              • Returns void

          Returns void

    Returns void

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

registerRouteWithAuth

  • registerRouteWithAuth(method: string, route: string, schema: Schema, authorize: function, action: function): void
  • Registers an action with authorization 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.

    • authorize: function

      the authorization interceptor

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

          • req: any
          • res: any
          • next: function
              • (): void
              • Returns void

          Returns void

    • 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

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

    see

    IRegisterable

    Parameters

    Returns void

Generated using TypeDoc