Skip to content

Create a common interface for protocol bindings  #72

@vcharpenay

Description

@vcharpenay

Currently, it seems that WoT consumers have to know in advance the protocol binding of a Thing. If a Thing has both an HTTP and a CoAP binding, a consumer has to decide statically whether to instantiate a TDHttpRequest or a TDCoapRequest from each form.

Would it be possible to instantiate a generic object representing a request (or, in the WoT terminology, an operation)? Here is a suggestion:

Optional<PropertyAffordance> humidity = td.getPropertyByName("humidity");

if (humidity.isPresent()) {
  Optional<Form> form = humidity.get().getFirstFormForOperationType(TD.readProperty);

  if(form.isPresent()) {
    // here is the proposal
    Operation op = ProtocolBindingFactory.bind(form.get(), TD.readProperty);
    op.setPayload();
    Response response = op.execute();

    // the response's interface is generic, it may include properties of the Expected Response class and a 'payload' property represented as JSON, as current TDHttpResponse objects
  }
}

Protocol bindings may register themselves to ProtocolBindingFactory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions