Interface IOnmsHTTP

Interface for making ReST calls to an HTTP server.

Notes to implementors:

  • Implementations of this interface MUST have a constructor that allows an empty constructor to be passed (although it is OK to take optional arguments for the purposes of unit testing or convenience).
  • Implementations MUST always use the current state of the server config property when creating requests. If the server property changes, the implementation should do whatever is necessary to reconfigure itself.
  • Implementations MUST follow this precedence for resolving the preferred [[OnmsServer]] object to use when making an individual connection:
    1. The server property on the passed [[OnmsHTTPOptions]] on individual method calls.
    2. The server property in the options property of the implementation.
    3. The server property of the implementation.
  • Implementations MUST follow this precedence for resolving the preferred [[OnmsAuthConfig]] to use when making an individual connection:
    1. The auth property on the passed [[OnmsHTTPOptions]] on individual method calls.
    2. The auth property on the options property of the implementation.
    3. The auth property on the server property of the implementation.

Note that if you subclass [[AbstractHTTP]], [[AbstractHTTP.getOptions]] will automatically provide you a hydrated [[OnmsHTTPOptions]] that handles most of this precedence for combining the server metadata.

interface IOnmsHTTP {
    options?: OnmsHTTPOptions;
    server?: OnmsServer;
    get(url, options?): Promise<OnmsResult<any>>;
    head(url, options?): Promise<OnmsResult<any>>;
    httpDelete(url, options?): Promise<OnmsResult<any>>;
    post(url, options?): Promise<OnmsResult<any>>;
    put(url, options?): Promise<OnmsResult<any>>;
}

Implemented by

Properties

options?: OnmsHTTPOptions

The default options used when making requests with this instance.

server?: OnmsServer

The server associated with this instance.

Methods

  • Perform an HTTP GET to the provided URL.

    Parameters

    • url: string

      The URL to connect to.

    • Optional options: OnmsHTTPOptions

      The [[OnmsHTTPOptions]] options to use when connecting.

    Returns Promise<OnmsResult<any>>

    An [[OnmsResult]] result object.

  • Perform an HTTP HEAD to the provided URL.

    Parameters

    • url: string

      The URL to connect to.

    • Optional options: OnmsHTTPOptions

      The [[OnmsHTTPOptions]] options to use when connecting.

    Returns Promise<OnmsResult<any>>

    An [[OnmsResult]] result object.

  • Perform an HTTP DELETE to the provided URL.

    Parameters

    • url: string

      The URL to connect to.

    • Optional options: OnmsHTTPOptions

      The [[OnmsHTTPOptions]] options to use when connecting.

    Returns Promise<OnmsResult<any>>

    An [[OnmsResult]] result object.

  • Perform an HTTP POST to the provided URL.

    Parameters

    • url: string

      The URL to connect to.

    • Optional options: OnmsHTTPOptions

      The [[OnmsHTTPOptions]] options to use when connecting.

    Returns Promise<OnmsResult<any>>

    An [[OnmsResult]] result object.

  • Perform an HTTP PUT to the provided URL.

    Parameters

    • url: string

      The URL to connect to.

    • Optional options: OnmsHTTPOptions

      The [[OnmsHTTPOptions]] options to use when connecting.

    Returns Promise<OnmsResult<any>>

    An [[OnmsResult]] result object.