Subscribing to Liberty REST API updates in a collective

Use the subscription API in the collective controller to immediately learn about new REST APIs, removed APIs, or changes to APIs such as changes in the endpoints from a specific collective member server.

Before you begin

The /ibm/api/collective/docs/subscription API is in the Liberty REST API discovery feature. To subscribe to updates to REST APIs from collective member servers, you must first complete the procedure in Discovering REST API documentation on a Liberty server for a collective controller.

Procedure

  1. Enable subscriptions.

    Add the websocket-1.0 or websocket-1.1 feature to the collective controller server.xml file; for example:

    
    <server>
       <featureManager>
          <feature>collectiveController-1.0</feature>
          <feature>apiDiscovery-1.0</feature>
          <feature>websocket-1.1</feature>
       </featureManager>
      
       <!-- some collective controller configurations are omitted -->
    
       <httpEndpoint id="defaultHttpEndpoint"
                     host="*"
                     httpPort="8010"
                     httpsPort="8020"/>
    
       <keyStore id="defaultKeyStore" password="Liberty"/>
    
       <basicRegistry id="basic" realm="ibm/api">
          <user name="bob" password="bobpwd" />
       </basicRegistry>
    </server>

    The /ibm/api/collective/docs/subscription endpoint enables POST requests with a JSON payload in the following format:

    { "docType" : String }

    String is either Swagger_20_JSON or Swagger_20_YAML. The returning JSON payload outlines the type of subscription feed and its URL.

    For example, the following request:

    {"docType":"Swagger_20_JSON"}

    returns a response such as:

    {
      "feedType": "websocket",
      "feedURL": "wss://myserver.com:8020/ibm/api/collective/docs/subscription/websocket/60db0d79-1863-48f5-a0f9-4fe22a27b82d"
    }
  2. Use a websocket client to connect to the feed URL.

    You can write code or use a third-party websocket client to connect to the feed URL.

    Once connected, any further updates to REST APIs in the Liberty server are pushed through the websocket. The update is either in JSON or YAML format, depending on the subscription.