Interactions-HSG / Interactions-HSG/wot-td-java
Create a common interface for protocol bindings
- Dominant language
- Java
- Stars
- 10
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
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:
```java
Optional humidity = td.getPropertyByName("humidity");
if (humidity.isPresent()) {
Optional 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`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.