-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a convenient way to fetch a TD in simple case #216
Comments
In the second case, for HTTP the new partial interface WoT {
Promise<ConsumedThing>consume(
(ThingDescription or ThingDescriptionURL) source,
optional ConsumeOptions options);
};
typedef (USVString or URL) ThingDescriptionURL;
dictionary ConsumeOptions {
// here come the options we need
}; The consume options could come for instance from Fetch RequestInit. Currently we don't need them IMHO. Also, URL is usually a string. However, it could also be a URL object. To be discussed. Now how it affects the implementation: if function consume(source) {
return new Promise((resolve, reject) =>
{
let td = null;
if (typeof source === 'string' || source instanceof URL) {
try {
let res = await fetch(source);
td = await res.json();
} catch { reject( new TypeError) };
} else if (typeof source === 'object') {
td = source;
} else reject(new TypeError);
resolve(new ConsumedThing(td));
});
}; |
The other way would be a separate function that would leave the current implementation of partial interface WoT {
Promise<ThingDescription> retrieve(
(USVString or URL) url,
optional RetrieveOptions options);
};
dictionary RetrieveOptions {
// here come the options we need
}; And its implementation would be similar to the one above. |
Note that yet another way to obtain TDs is via discovery. let discovery = new ThingDiscovery(
{
url: "https://mythings.org/sensor11",
method: "direct"
});
// note that fetch options could be merged with discovery options
do {
let td = await discovery.next();
console.log("Found Thing Description for " + td.title);
let thing = new ConsumedThing(td);
console.log("Thing name: " + thing.getThingDescription().title);
} while (!discovery.done); It's another thing the Discovery API is going to likely change, so there are some options forward. |
I see the point that the discovery work should provide means to easily get/retrieve a TD (and this might even change the following opinion in the future). Having said that, I still like the current Scripting API approach that does not go into all those details how and where to retrieve a TD. The "assumption" is that once you do |
I have a positive feedback for the Discovery proposal. I think it blends quite well with what we have already. Plus it does not require to define a fetch like function. I still believe that we need this method even if COAP over UDP might cause some troubles... |
Yes, I had the same thoughts just before checking on this issue :). Makes sense. |
Note: I suggest to remove the F2F label and re-label it with discovery and enhancement |
I think we now have such a method in place, therefore I added the |
Please add a ref to the PR that fixes this, and then close. |
Call 11 Dec
|
As discussed on the Scripting call on 1 June 2020,
In the past, the Scripting API had two ways to do this:
fetch()
orfetchTD
orfetchDescription()
call that took a URL as a parameter and resolved with a parsed JSON object.consume()
method (either a URL or a TD object was given as parameter).Edit. Some historical discussions in these issues:
#162
#78
The text was updated successfully, but these errors were encountered: