RestServer (Java Application API for IBM Streams)
Date: 2020-08-07

com.ibm.streamsx.topology.inet

## Class RestServer

- java.lang.Object
- - com.ibm.streamsx.topology.inet.RestServer

-     public class RestServer
      extends java.lang.Object

  Adds a HTTP REST server to a topology to provide external interaction with the application.
  See Also:
    com.ibm.streamsx.inet

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RestServer(TopologyElement te, int port)` Create a REST server that will listen on the specified port.
    `RestServer(TopologyElement te)` Create a REST server that will listen on port 8080.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Topology` | `topology()` Get the topology for this REST server.
    `java.lang.String` | `viewer(TWindow<?,?> window, java.lang.String context, java.lang.String name)` Declare a HTTP REST view of tuples in a window.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RestServer

          public RestServer(TopologyElement te)

      Create a REST server that will listen on port 8080.
      Parameters:
        `te` - Topology to contain the REST server.

    - #### RestServer

          public RestServer(TopologyElement te,
                            int port)

      Create a REST server that will listen on the specified port.
      Parameters:
        `te` - Topology to contain the REST server.
        `port` - Port to listen on.

  - ### Method Detail

    - #### topology

          public Topology topology()

      Get the topology for this REST server.
      Returns:
        Topology for this server.

    - #### viewer

          public java.lang.String viewer(TWindow<?,?> window,
                                         java.lang.String context,
                                         java.lang.String name)

      Declare a HTTP REST view of tuples in a window. A HTTP GET to the the server at runtime will return the current contents of the window as an array of JSON objects, with each tuple converted to a JSON object.
      Conversion to JSON depends on the type of stream that populates `window`.
      - `TStream<JSONObject>` - Each tuple is the JSON object.
      - `TStream<? extends JSONAble>` - Each tuple is converted to a JSON object using `JSONAble.toJSON()`.
      - `TStream<String>` - Each tuple will be converted to a JSON object with a single attribute '`string`' with the tuple's value.
      - `SPLStream` - Each `Tuple` is converted to JSON using the encoding provided by the Java Operator API `com.ibm.streams.operator.encoding.JSONEncoding`.
      Other stream types are not supported.
      Parameters:
        `window` - Window to expose through the HTTP GET
        `context` - Context path for the URL to access the resource.
        `name` - Relative name (to `context`) of the resource.
      Returns:
        null (future will be the path to the tuples)