This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

Functions - websub

addWebSubLinkHeader

Function to add link headers to a response to allow WebSub discovery.

extractTopicAndHubUrls

Retrieves hub and topic URLs from the http:response from a publisher to a discovery request.

startHub

Starts up the Ballerina Hub.

addWebSubLinkHeader

(Response response, string[] hubs, string topic)

Function to add link headers to a response to allow WebSub discovery.

Parameters

  • response Response
  • The response being sent

  • hubs string[]
  • The hubs the publisher advertises as the hubs that it publishes updates to

  • topic string
  • The topic to which subscribers need to subscribe to, to receive updates for the resource

extractTopicAndHubUrls

(Response response)

returns [string, string[]] | error

Retrieves hub and topic URLs from the http:response from a publisher to a discovery request.

Parameters

  • response Response
  • An http:Response received

  • Return Type

    ([string, string[]] | error)
  • A (topic, hubs) if parsing and extraction is successful or else an error if not

startHub

(Listener hubServiceListener, string basePath, string subscriptionResourcePath, string publishResourcePath, ServiceAuth serviceAuth, ResourceAuth subscriptionResourceAuth, ResourceAuth publisherResourceAuth, string? publicUrl, HubConfiguration hubConfiguration)

returns Hub | HubStartedUpError | HubStartupError

Starts up the Ballerina Hub.

  websub:Hub|websub:HubStartedUpError|websub:HubStartupError webSubHub = websub:startHub(new http:Listener(9191),
 "/websub", "/hub");

Parameters

  • hubServiceListener Listener
  • The http:Listener to which the hub service is attached

  • basePath string (default /)
  • The base path of the hub service

  • subscriptionResourcePath string (default /)
  • The resource path for subscription changes

  • publishResourcePath string (default /publish)
  • The resource path for publishing and topic registration

  • serviceAuth ServiceAuth (default {enabled: false})
  • The auth configuration for the hub service

  • subscriptionResourceAuth ResourceAuth (default {enabled: false})
  • The auth configuration for the subscription resource of the hub service

  • publisherResourceAuth ResourceAuth (default {enabled: false})
  • The auth configuration for the publisher resource of the hub service

  • publicUrl string? (default ())
  • The URL for the hub for remote interaction; used in defining the subscription and publish URLs. The subscription URL is defined as {publicUrl}/{basePath}/{subscriptionResourcePath} if publicUrl is specified, defaults to http(s)://localhost:{port}/{basePath}/{subscriptionResourcePath} if not. The publish URL is defined as {publicUrl}/{basePath}/{publishResourcePath} if publicUrl is specified, defaults to http(s)://localhost:{port}/{basePath}/{publishResourcePath} if not.

  • Return Type

    (Hub | HubStartedUpError | HubStartupError)
  • A newly started WebSub Hub or else a websub:HubStartedUpError indicating that the hub is already started, and including the websub:Hub object representing the already started up hub