Skip to content

Commit 598140c

Browse files
docs: use requestThingDescription() instead of fetch in examples
1 parent fe43a9c commit 598140c

4 files changed

Lines changed: 10 additions & 19 deletions

File tree

API.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Interacting with another WoT Thing is called consuming a Thing and works by usin
245245
##### Fetch a Thing Description of a Thing given its URL
246246
247247
```javascript
248-
WoTHelpers.fetch("http://localhost:8080/counter").then(async(td) => {
248+
WoT.requestThingDescription("http://localhost:8080/counter").then(async(td) => {
249249
// Do something with the TD
250250
}
251251
```
@@ -255,13 +255,13 @@ URLs can have various schemes, including `file://` to read from the local filesy
255255
##### Consume a TD of a Thing, including parsing the TD and generating the protocol bindings in order to access lower level functionality
256256

257257
```javascript
258-
WoTHelpers.fetch("http://localhost:8080/counter").then(async (td) => {
258+
WoT.requestThingDescription("http://localhost:8080/counter").then(async (td) => {
259259
let thing = WoT.consume(td);
260260
// Do something with the consumed Thing
261261
});
262262
```
263263

264-
Things can be `consume`d no matter if they were fetched with WoTHelpers or not.
264+
Things can be `consume`d no matter if they were fetched with `WoT.requestThingDescription()`, `WoTHelpers.fetch()` or any other mean.
265265
`consume` only requires a TD as an `Object`, so you could also use `fs.readFile` and `JSON.parse` or inline it into your code.
266266
As long at it results in a TD Object, you can receive it over Fax, Morse it or use smoke signals.
267267

@@ -298,10 +298,10 @@ It is an asynchronous function that will take some time to complete.
298298
So you should handle it explicitly.
299299
Here we use the `async`/`await` functionality of NodeJS.
300300
301-
Declare the surrounding function as `async`, e.g., the `WoTHelpers.fetch()` resolve handler:
301+
Declare the surrounding function as `async`, e.g., the `WoT.requestThingDescription()` resolve handler:
302302
303303
```javascript
304-
WoTHelpers.fetch(myURI).then(async(td) => { ... });
304+
WoT.requestThingDescription(myURI).then(async(td) => { ... });
305305
```
306306
307307
Use `await` to make Promises synchronous (blocking):

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,13 @@ Now supposing you want to interact with the device, you have to consume its Thin
180180
```JavaScript
181181
// client.js
182182
// Required steps to create a servient for a client
183-
const { Servient, Helpers } = require("@node-wot/core");
183+
const { Servient } = require("@node-wot/core");
184184
const { HttpClientFactory } = require('@node-wot/binding-http');
185185

186186
const servient = new Servient();
187187
servient.addClientFactory(new HttpClientFactory(null));
188-
const WoTHelpers = new Helpers(servient);
189188

190-
WoTHelpers.fetch("http://localhost:8080/counter").then(async (td) => {
189+
WoT.requestThingDescription("http://localhost:8080/counter").then(async (td) => {
191190
try {
192191
const WoT = await servient.start();
193192
// Then from here on you can consume the thing

packages/binding-coap/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ The Thing Description is located under the following CoAP URI `coap://plugfest.t
2626

2727
```js
2828
// example-client.js
29-
const { Servient, Helpers } = require("@node-wot/core");
29+
const { Servient } = require("@node-wot/core");
3030
const { CoapClientFactory } = require("@node-wot/binding-coap");
3131

3232
// create Servient and add CoAP binding
3333
const servient = new Servient();
3434
servient.addClientFactory(new CoapClientFactory());
3535

36-
const wotHelper = new Helpers(servient);
37-
wotHelper
38-
.fetch("coap://plugfest.thingweb.io:5683/testthing")
36+
WoT.requestThingDescription("coap://plugfest.thingweb.io:5683/testthing")
3937
.then(async (td) => {
40-
// using await for serial execution (note 'async' in then() of fetch())
4138
try {
4239
const WoT = await servient.start();
4340
const thing = await WoT.consume(td);

packages/binding-http/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,12 @@ The Thing Description is located under the following uri <http://plugfest.thingw
2929
Servient = require("@node-wot/core").Servient;
3030
HttpClientFactory = require("@node-wot/binding-http").HttpClientFactory;
3131

32-
Helpers = require("@node-wot/core").Helpers;
33-
3432
// create Servient and add HTTP binding
3533
let servient = new Servient();
3634
servient.addClientFactory(new HttpClientFactory(null));
3735

38-
let wotHelper = new Helpers(servient);
39-
wotHelper
40-
.fetch("http://plugfest.thingweb.io:8083/testthing")
36+
WoT.requestThingDescription("http://plugfest.thingweb.io:8083/testthing")
4137
.then(async (td) => {
42-
// using await for serial execution (note 'async' in then() of fetch())
4338
try {
4439
const WoT = await servient.start();
4540
const thing = await WoT.consume(td);

0 commit comments

Comments
 (0)