Skip to content

Commit fe43a9c

Browse files
refactor: favor WoT.requestThingDescription instead of general fetch
1 parent 8761e64 commit fe43a9c

10 files changed

Lines changed: 18 additions & 50 deletions

File tree

examples/scripts/counter-client.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ function getFormIndexForDecrementWithCoAP(thing) {
2626
// return formIndex: 0 if no CoAP target IRI found
2727
return 0;
2828
}
29-
WoTHelpers.fetch("coap://localhost:5683/counter")
29+
WoT.requestThingDescription("coap://localhost:5683/counter")
3030
.then(async (td) => {
31-
// using await for serial execution (note 'async' in then() of fetch())
3231
try {
3332
const thing = await WoT.consume(td);
3433
console.info("=== TD ===");

examples/scripts/smart-coffee-machine-client.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
// This is an example of Web of Things consumer ("client" mode) Thing script.
1616
// It considers a fictional smart coffee machine in order to demonstrate the capabilities of Web of Things.
1717
// An accompanying tutorial is available at http://www.thingweb.io/smart-coffee-machine.html.
18-
1918
// Print data and an accompanying message in a distinguishable way
2019
function log(msg, data) {
2120
console.info("======================");
2221
console.info(msg);
2322
console.dir(data);
2423
console.info("======================");
2524
}
26-
WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) => {
25+
WoT.requestThingDescription("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) => {
2726
try {
2827
const thing = await WoT.consume(td);
2928
log("Thing Description:", td);

examples/security/oauth/consumer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414
********************************************************************************/
15-
WoTHelpers.fetch("https://localhost:8080/oauth").then((td) => {
15+
WoT.requestThingDescription("https://localhost:8080/oauth").then((td) => {
1616
WoT.consume(td).then(async (thing) => {
1717
try {
1818
const resp = await thing.invokeAction("sayOk");

examples/testthing/testclient.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ async function testPropertyWrite(thing, name, value, shouldFail) {
3939
else console.info("PASS " + name + " WRITE (" + displayValue + "):", JSON.stringify(err));
4040
}
4141
}
42-
WoTHelpers.fetch("http://localhost:8080/testthing")
42+
WoT.requestThingDescription("http://localhost:8080/testthing")
4343
.then(async (td) => {
44-
// using await for serial execution (note 'async' in then() of fetch())
4544
try {
4645
const thing = await WoT.consume(td);
4746
console.info("=== TD ===");

packages/examples/src/bindings/coap/example-client.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@
1313
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414
********************************************************************************/
1515

16-
import { Servient, Helpers } from "@node-wot/core";
16+
import { Servient } from "@node-wot/core";
1717
import { CoapClientFactory } from "@node-wot/binding-coap";
18-
import { ThingDescription } from "wot-typescript-definitions";
1918

2019
// create Servient and add CoAP binding
2120
const servient = new Servient();
2221
servient.addClientFactory(new CoapClientFactory());
2322

24-
const wotHelper = new Helpers(servient);
25-
wotHelper
26-
.fetch("coap://plugfest.thingweb.io:5683/testthing")
27-
.then(async (fetched) => {
28-
const td: ThingDescription = fetched as ThingDescription;
29-
// using await for serial execution (note 'async' in then() of fetch())
23+
WoT.requestThingDescription("coap://plugfest.thingweb.io:5683/testthing")
24+
.then(async (td) => {
3025
try {
3126
const WoT = await servient.start();
3227
const thing = await WoT.consume(td);

packages/examples/src/bindings/http/example-client.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@
1313
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414
********************************************************************************/
1515

16-
import { Servient, Helpers } from "@node-wot/core";
16+
import { Servient } from "@node-wot/core";
1717
import { HttpClientFactory } from "@node-wot/binding-http";
18-
import { ThingDescription } from "wot-typescript-definitions";
1918

2019
// create Servient and add HTTP binding
2120
const servient = new Servient();
2221
servient.addClientFactory(new HttpClientFactory());
2322

24-
const wotHelper = new Helpers(servient);
25-
wotHelper
26-
.fetch("http://plugfest.thingweb.io:8083/testthing")
27-
.then(async (fetched) => {
28-
const td: ThingDescription = fetched as ThingDescription;
29-
// using await for serial execution (note 'async' in then() of fetch())
23+
WoT.requestThingDescription("http://plugfest.thingweb.io:8083/testthing")
24+
.then(async (td) => {
3025
try {
3126
const WoT = await servient.start();
3227
const thing = await WoT.consume(td);

packages/examples/src/scripts/counter-client.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414
********************************************************************************/
1515

16-
import { Helpers } from "@node-wot/core";
17-
import { ThingDescription } from "wot-typescript-definitions";
18-
19-
let WoTHelpers!: Helpers;
20-
2116
function getFormIndexForDecrementWithCoAP(thing: WoT.ConsumedThing): number {
2217
const forms = thing.getThingDescription().actions?.decrement.forms;
2318
if (forms !== undefined) {
@@ -31,11 +26,10 @@ function getFormIndexForDecrementWithCoAP(thing: WoT.ConsumedThing): number {
3126
return 0;
3227
}
3328

34-
WoTHelpers.fetch("coap://localhost:5683/counter")
29+
WoT.requestThingDescription("coap://localhost:5683/counter")
3530
.then(async (td) => {
36-
// using await for serial execution (note 'async' in then() of fetch())
3731
try {
38-
const thing = await WoT.consume(td as ThingDescription);
32+
const thing = await WoT.consume(td);
3933
console.info("=== TD ===");
4034
console.info(td);
4135
console.info("==========");

packages/examples/src/scripts/smart-coffee-machine-client.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
// It considers a fictional smart coffee machine in order to demonstrate the capabilities of Web of Things.
1818
// An accompanying tutorial is available at http://www.thingweb.io/smart-coffee-machine.html.
1919

20-
import { ThingDescription } from "wot-typescript-definitions";
21-
import { Helpers } from "@node-wot/core";
22-
let WoTHelpers!: Helpers;
23-
2420
// Print data and an accompanying message in a distinguishable way
2521
function log(msg: string, data: unknown) {
2622
console.info("======================");
@@ -29,9 +25,9 @@ function log(msg: string, data: unknown) {
2925
console.info("======================");
3026
}
3127

32-
WoTHelpers.fetch("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) => {
28+
WoT.requestThingDescription("http://127.0.0.1:8080/smart-coffee-machine").then(async (td) => {
3329
try {
34-
const thing = await WoT.consume(td as ThingDescription);
30+
const thing = await WoT.consume(td);
3531
log("Thing Description:", td);
3632

3733
// Read property allAvailableResources

packages/examples/src/security/oauth/consumer.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212
*
1313
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414
********************************************************************************/
15-
import { Helpers } from "@node-wot/core";
16-
import { ThingDescription } from "wot-typescript-definitions";
1715

18-
let WoTHelpers!: Helpers;
19-
20-
WoTHelpers.fetch("https://localhost:8080/oauth").then((td) => {
21-
WoT.consume(td as ThingDescription).then(async (thing) => {
16+
WoT.requestThingDescription("https://localhost:8080/oauth").then((td) => {
17+
WoT.consume(td).then(async (thing) => {
2218
try {
2319
const resp = await thing.invokeAction("sayOk");
2420
const result = await resp?.value();

packages/examples/src/testthing/testclient.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414
********************************************************************************/
1515

16-
import { Helpers } from "@node-wot/core";
17-
import { ThingDescription } from "wot-typescript-definitions";
18-
let WoTHelpers!: Helpers;
19-
2016
console.log = () => {
2117
/* empty */
2218
};
@@ -51,11 +47,10 @@ async function testPropertyWrite(
5147
}
5248
}
5349

54-
WoTHelpers.fetch("http://localhost:8080/testthing")
50+
WoT.requestThingDescription("http://localhost:8080/testthing")
5551
.then(async (td) => {
56-
// using await for serial execution (note 'async' in then() of fetch())
5752
try {
58-
const thing = await WoT.consume(td as ThingDescription);
53+
const thing = await WoT.consume(td);
5954
console.info("=== TD ===");
6055
console.info(td);
6156
console.info("==========");

0 commit comments

Comments
 (0)