-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.html
1068 lines (1064 loc) · 40.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Web Thing API</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script class="remove">
var respecConfig = {
specStatus: "unofficial",
editors: [
{
name: "Ben Francis",
company: "Krellian",
companyURL: "https://krellian.com/",
w3cid: 51527
}
],
processVersion: 2018,
edDraftURI: "https://webthings.io/api",
shortName: "WoT",
localBiblio: {
"web-linking": {
title: "Web Linking",
href: "https://tools.ietf.org/html/rfc5988",
publisher: "IETF",
},
},
};
</script>
<style>
table {
width: 100%;
border: solid 1px #005a9c;
border-collapse: collapse;
}
th {
background-color: #005a9c;
color: white;
}
td,
th {
border: solid 1px #005a9c;
padding: 4px;
}
</style>
</head>
<body>
<section id="abstract">
<p>
This document describes a common data model and API for the Web of Things. The <a href="#web-thing-description">Web Thing Description</a> provides a vocabulary for describing physical devices connected to the World Wide Web in a
machine readable format with a default JSON encoding. Common device capabilities can be specified using optional <a href="#context-member">semantic annotations</a>. The <a href="#web-thing-rest-api">Web Thing REST API</a> and
<a href="#web-thing-websocket-api">Web Thing WebSocket API</a> allow a web client to access the properties of devices, request the execution of actions and subscribe to events representing a change in state.
</p>
</section>
<section id="sotd">
<p>Note that the <a href="#web-thing-description">Web Thing Description</a> section is currently being <a href="https://www.w3.org/TR/wot-thing-description/">standardised</a> by the <a href="https://www.w3.org/WoT/WG/">W3C Web of Things Working Group</a> and the <a href="#web-thing-rest-api">Web Thing REST API</a> and <a href="#web-thing-websocket-api">Web Thing WebSocket API</a> sections are being standardised by the <a href="https://www.w3.org/community/web-thing-protocol/">W3C Web Thing Protocol Community Group</a>.</p>
<p>This specification started as a draft W3C member submission by <a href="https://www.mozilla.org">Mozilla</a>, but continues to be maintained to document the API currently implemented by the <a href="https://webthings.io/">WebThings</a> IoT platform while it converges with the W3C standards as they mature.</p>
</section>
<section>
<h2>Introduction</h2>
<p>
The goal of the Web of Things is to extend the web of pages into a web of things by giving connected devices URLs on the World Wide Web. This will allow the web to be used as a unifying application layer for a decentralized Internet
of Things.
</p>
<p>
Whilst web technologies are already in widespread use on the Internet of Things, this is currently done with mostly proprietary data formats and APIs which require per-vendor integrations to make devices interoperable. In order to
promote ad-hoc interoperability on the Internet of Things a shared vocabulary and common API is needed.
</p>
<p>In this document we propose a common data model and API for the Web of Things.</p>
</section>
<section>
<h2>Web Thing Description</h2>
<p>The Thing Description provides a vocabulary for describing physical devices connected to the World Wide Web in a machine readable format with a default JSON encoding.</p>
<pre class="example" title="A simple Thing Description">
{
"id": "https://mywebthingserver.com/things/switch",
"title": "On/Off Switch",
"description": "A web connected switch",
"properties": {
"on": {
"title": "On/Off",
"type": "boolean",
"description": "Whether the lamp is turned on",
"links": [{"href": "/things/switch/properties/on"}]
}
}
}
</pre>
<pre class="example" title="A more complex Thing Description with semantic annotations">
{
"@context": "https://webthings.io/schemas/",
"@type": ["Light", "OnOffSwitch"],
"id": "https://mywebthingserver.com/things/lamp",
"title": "My Lamp",
"description": "A web connected lamp",
"properties": {
"on": {
"@type": "OnOffProperty",
"type": "boolean",
"title": "On/Off",
"description": "Whether the lamp is turned on",
"links": [{"href": "/things/lamp/properties/on"}]
},
"brightness" : {
"@type": "BrightnessProperty",
"type": "integer",
"title": "Brightness",
"description": "The level of light from 0-100",
"minimum" : 0,
"maximum" : 100,
"links": [{"href": "/things/lamp/properties/brightness"}]
}
},
"actions": {
"fade": {
"@type": "FadeAction",
"title": "Fade",
"description": "Fade the lamp to a given level",
"input": {
"type": "object",
"properties": {
"level": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"duration": {
"type": "integer",
"minimum": 0,
"unit": "milliseconds"
}
}
},
"links": [{"href": "/things/lamp/actions/fade"}]
}
},
"events": {
"overheated": {
"title": "Overheated",
"@type": "OverheatedEvent",
"type": "number",
"unit": "degree celsius",
"description": "The lamp has exceeded its safe operating temperature",
"links": [{"href": "/things/lamp/events/overheated"}]
}
},
"links": [
{
"rel": "properties",
"href": "/things/lamp/properties"
},
{
"rel": "actions",
"href": "/things/lamp/actions"
},
{
"rel": "events",
"href": "/things/lamp/events"
},
{
"rel": "alternate",
"href": "wss://mywebthingserver.com/things/lamp"
},
{
"rel": "alternate",
"mediaType": "text/html",
"href": "/things/lamp"
}
]
}
</pre>
<section>
<h3><code>@context</code> member</h3>
<p>
The <code>@context</code> member is an optional annotation which can be used to provide a URI for a schema repository which defines standard schemas for common "types" of device capabilities. These types can then be referred to
using <code>@type</code> annotations elsewhere in the Thing Description.
</p>
<div class="note">Example experimental schema repositories can be found at <a href="http://iotschema.org/">http://iotschema.org/</a> and <a href="https://webthings.io/schemas">https://webthings.io/schemas</a>.</div>
<pre class="example" title="Example @context member">"@context": "https://webthings.io/schemas"</pre>
</section>
<section>
<h3><code>@type</code> member</h3>
<p>
The <code>@type</code> member is an optional annotation which can be used to provide the names of schemas for types of capabilities a device supports, from a schema repository referred to in the <code>@context</code> member. The
value of the <code>@type</code> member is a string or an array of strings which correspond to schema names from a schema repository.
</p>
<p>
Providing a <code>@type</code> annotation tells a client that it can expect the device to conform to the constraints of that type's schema. This may include certain types of property, action and event the device can be expected to
support. A client may make use of this information to aid in automation of or to generate a user interface for known standard device capabilities.
</p>
<pre class="example" title="Example @type member">"@type": ["Light", "OnOffSwitch"]</pre>
</section>
<section>
<h3><code>id</code> member</h3>
<p>The id member provides an identifier of the device in the form of a URI [[RFC3986]] (e.g. a URL or a URN). This may be the URL of the Thing Description itself, but can be any URI.</p>
<pre class="example" title="Example id member">"id": "https://mywebthingserver.com/things/lamp"</pre>
</section>
<section>
<h3><code>title</code> member</h3>
<p>The title member is a human friendly string which describes the device. This can be set to any value by the device creator and may include a brand name or model number.</p>
</section>
<section>
<h3><code>description</code> member</h3>
<p>The description member is a human friendly string which describes the device and its functions. This can be set to any value by the device creator.</p>
</section>
<section>
<h3><code>properties</code> member</h3>
<p>The properties member is a map of <a href="#property-object">Property objects</a> which describe the attributes of the device.</p>
</section>
<section>
<h3><code>actions</code> member</h3>
<p>
The actions member is a map of <a href="#action-object">Action objects</a> which describe functions that can be carried out on a device. Actions are used when the setting of a property alone is not sufficient to affect a required
change in state. This may be used to describe a function which takes a period of time to complete, manipulates multiple properties, or has a different outcome based on provided arguments or current state. An example might include
a "fade" action which has a specified "duration", a "sequence" action which triggers a sequence of flashing lights or a "toggle" action on a switch.
</p>
</section>
<section>
<h3><code>events</code> member</h3>
<p>
The events member is a map of <a href="#event-object">Event objects</a> which define the types of events which may be emitted by a device. Events can be used where subscribing to a change in property state is not sufficient. This
may be used to monitor changes in multiple properties or events which describe something other than a property change. An example might be an event which is emitted when a device is about to reboot.
</p>
</section>
<section>
<h3><code>links</code> member</h3>
<p>The links member provides an array of <a href="#link-object">Link Object</a>s which link to other resources of a thing.</p>
<p>
Examples of links include a link to a <a href="#properties-resource">Properties resource</a> (<code>"rel":"properties"</code>), an <a href="#actions-resource">Actions resource</a> (<code>"rel":"actions"</code>) or an
<a href="#events-resource">Events resource</a> (<code>"rel":"events"</code>). It can also include links to alternate representations of a thing such as a WebSocket API endpoint or an HTML user interface
(<code>"rel":"alternate"</code>).
</p>
<pre class="example" title="Example links member">
"links": [
{
"rel": "properties",
"href": "/things/lamp/properties"
},
{
"rel": "actions",
"href": "/things/lamp/actions"
},
{
"rel": "events",
"href": "/things/lamp/events"
},
{
"rel": "alternate",
"href": "wss://mywebthingserver.com/things/lamp"
},
{
"rel": "alternate",
"mediaType": "text/html",
"href": "/things/lamp"
}
]
</pre>
</section>
<section>
<h3><code>Property</code> object</h3>
<p>A property object describes an attribute of a Thing and is indexed by a property id. A property description may include:</p>
<ul>
<li>A primitive <code>type</code> (one of null, boolean, object, array, number, integer or string as per [[!json-schema]])</li>
<li>
A semantic <code>@type</code> (a string identifying a type from the linked <a href="#context-member"><code>@context</code></a>)
</li>
<li>A <code>unit</code> ([[!SI]] unit)</li>
<li>A <code>title</code> (A string providing a human friendly name)</li>
<li>A <code>description</code> (A string providing a human friendly description)</li>
<li>
A <code>links</code> array (An array of <a href="#link-object">Link object</a>s linking to one or more representations of a <a href="#property-resource">Property resource</a>, each with an implied default
<code>rel=property</code>.)
</li>
<li><code>enum</code> (an enumeration of possible values for the property)</li>
<li><code>readOnly</code> (A boolean indicating whether or not the property is read-only, defaulting to false)</li>
<li>A <code>minimum</code> and <code>maximum</code> (numeric values)</li>
<li><code>multipleOf</code> (A number indicating what the value must be a multiple of)</li>
</ul>
<pre class="example" title="Property Object">
"level" : {
"title": "Level",
"description": "The level of light from 0-100",
"@type": "LevelProperty",
"type": "integer",
"unit": "percent",
"minimum": 0,
"maximum": 100,
"readOnly": false,
"links": [{"href": "/things/lamp/properties/level"}]
}
</pre>
</section>
<section>
<h3><code>Action</code> object</h3>
<p>An action object describes a function which can be carried out on a device. An action definition may include:</p>
<ul>
<li>A <code>title</code> (A string providing a human friendly name)</li>
<li>A <code>description</code> (A string providing a human friendly description)</li>
<li>
A <code>links</code> array (An array of <a href="#link-object">Link object</a>s linking to one or more representations of an <a href="#action-resource">Action resource</a>, each with an implied default <code>rel=action</code>.)
</li>
<li>
An <code>input</code> object with a:
<ul>
<li>A primitive <code>type</code> (one of null, boolean, object, array, number, integer or string as per [[!json-schema]])</li>
<li>
A semantic <code>@type</code> (a string identifying a type from the linked <a href="#context-member"><code>@context</code></a>)
</li>
<li>A <code>unit</code> ([[!SI]] unit)</li>
<li>A <code>minimum</code> and <code>maximum</code> (numeric values)</li>
<li><code>multipleOf</code> (A number indicating what the value must be a multiple of)</li>
</ul>
</li>
</ul>
<pre class="example" title="Action Object">
"fade": {
"@type": "FadeAction",
"title": "Fade",
"description": "Fade the lamp to a given level",
"input": {
"type": "object",
"properties": {
"level": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"duration": {
"type": "integer",
"minimum": 0,
"unit": "milliseconds"
}
}
},
"links": [{"href": "/things/lamp/actions/fade"}]
}
</pre>
</section>
<section>
<h3><code>Event</code> object</h3>
<p>An event object describes a kind of event which may be emitted by a device. This may include:</p>
<ul>
<li>A primitive <code>type</code> (one of null, boolean, object, array, number, integer or string as per [[!json-schema]])</li>
<li>
A semantic <code>@type</code> (a string identifying a type from the linked <a href="#context-member"><code>@context</code></a>)
</li>
<li>A <code>unit</code> ([[!SI]] unit)</li>
<li>A <code>title</code> (A string providing a human friendly name)</li>
<li>A <code>description</code> (A string providing a human friendly description)</li>
<li>
A <code>links</code> array (An array of <a href="#link-object">Link object</a>s linking to one or more representations of an <a href="#event-resource">Event resource</a>, each with an implied default <code>rel=event</code>).
</li>
<li>A <code>minimum</code> and <code>maximum</code> (numeric values)</li>
<li><code>multipleOf</code> (A number indicating what the value must be a multiple of)</li>
</ul>
<pre class="example" title="Event Object">
"overheated": {
"title": "Overheated",
"description": "The lamp has exceeded its safe operating temperature",
"@type": "OverheatedEvent",
"type": "number",
"unit": "degree celsius",
"links": [{"href": "/things/lamp/events/overheated"}]
}
</pre>
</section>
<section>
<h3><code>Link</code> object</h3>
<p>A link object represents a link relation ([[!web-linking]]) and may have a:</p>
<ul>
<li><code>href</code> (a string representation of a URL)</li>
<li><code>rel</code> (a string describing a relationship)</li>
<li><code>mediaType</code> (a string identifying a media type)</li>
</ul>
<pre class="example" title="Link Object">
{
"href": "/things/lamp/properties",
"rel": "properties",
"mediaType": "application/json"
}
</pre>
</section>
<section>
<h3>Media Type</h3>
<p>The JSON serialization of the Web Thing Description is identified by the Media Type <code>application/td+json</code>.</p>
<div class="note">This media type has not yet been registered with IANA.</div>
</section>
<section>
<h3>Alternative Encodings</h3>
<p>The default encoding for the Thing description is JSON, but other encodings such as XML, JSON-LD or CBOR may be used. Alternative encodings are beyond the scope of this specification but may be defined separately.</p>
<p>References to alternative available encodings may be provided using Link HTTP response headers with the alternate link relation. A client can express a preference for an alternative encoding using HTTP content negotiation.</p>
</section>
</section>
<section>
<h2>Web Thing REST API</h2>
<p>
The Web Thing API provides a web services based programming interface with a RESTful design for applications to access the properties of devices, request the execution of actions and access a list of events representing a change in
state. A default HTTP [[!HTTP11]] protocol binding is defined here.
</p>
<p>
The Web Thing REST API consists of a number of different types of resources which represent different aspects of a device and can be independently referenced by a URL. The specific URLs and URL structure of resources are defined by
the Thing Description. This specification does <strong>not</strong> define a fixed URL structure.
</p>
<section>
<h3><code>Thing</code> resource</h3>
<p>A thing Resource provides a <a href="#web-thing-description">Thing Description</a> for a device. A Thing Resource is considered the root resource of a Thing.</p>
<p>The URL of a Thing Resource may be enumerated by the <code>href</code> member of Thing object in a <a href="#things-resource">Things Resource</a> provided by a gateway or directory, or may be discovered by some other means.</p>
<p>A Thing description is usually read only. An HTTP GET request can be used to retrieve a Thing Description for a Thing.</p>
<p><strong>Example: Get a description of a Thing</strong></p>
<div class="example">
<div class="example-title marker">
<span>Request</span>
</div>
<pre>
GET http://mythingserver.com/things/pi
Accept: application/json
</pre>
</div>
<div class="example">
<div class="example-title marker">
<span>Response</span>
</div>
<pre>
200 OK
{
"id": "https://mywebthingserver.com/things/pi",
"title": "WoT Pi",
"description": "A WoT-connected Raspberry Pi",
"properties": {
"temperature": {
"title": "Temperature",
"type": "number",
"unit": "degree celsius",
"readOnly": true,
"description": "An ambient temperature sensor",
"links": [{"href": "/things/pi/properties/temperature"}]
},
"humidity": {
"title": "Humidity",
"type": "number",
"unit": "percent",
"readOnly": true,
"links": [{"href": "/things/pi/properties/humidity"}]
},
"led": {
"title": "LED",
"type": "boolean",
"description": "A red LED",
"links": [{"href": "/things/pi/properties/led"}]
}
},
"actions": {
"reboot": {
"title": "Reboot",
"description": "Reboot the device"
}
},
"events": {
"reboot": {
"description": "Going down for reboot"
}
},
"links": [
{
"rel": "properties",
"href": "/things/pi/properties"
},
{
"rel": "actions",
"href": "/things/pi/actions"
},
{
"rel": "events",
"href": "/things/pi/events"
},
{
"rel": "alternate",
"href": "wss://mywebthingserver.com/things/pi"
},
{
"rel": "alternate",
"mediaType": "text/html",
"href": "/things/pi"
}
]
}
</pre>
</div>
</section>
<section>
<h3><code>Properties</code> resource</h3>
<p>A properties resource represents all the properties of a device. The value of all properties can be retrieved with an HTTP GET request.</p>
<p>
The URL of a Properties resource can be defined by a <code>properties</code> link relation in the <a href="#links-member"><code>links</code> member</a> of a Thing Description.
</p>
<p><strong>Example: Get all properties</strong></p>
<div class="example">
<div class="example-title marker">
Request
</div>
<pre>
GET http://mythingserver.com/things/pi/properties
Accept: application/json
</pre>
</div>
<div class="example">
<div class="example-title marker">
Response
</div>
<pre>
200 OK
{
"temperature": 21,
"humidity": 50,
"led": true
}
</pre>
</div>
</section>
<section>
<h3><code>Property</code> resource</h3>
<p>
A property resource represents a single property of a device. Some property resources may be read only and some may be writable. The value of a property can be retrieved with an HTTP GET request and updated with an HTTP PUT
request.
</p>
<p>The URL of a Property resource can be defined by the <code>links</code> section of a <a href="#property-object">Property object</a> in a Thing Description.</p>
<p>If a Property object does not define a primitive <code>type</code> it may not have a JSON serialisation and may instead return a binary file or stream in response to an HTTP GET request (e.g. an image file or video stream).</p>
<p><strong>Example: Get a property</strong></p>
<div class="example">
<div class="example-title marker">
Request
</div>
<pre>
GET http://mythingserver.com/things/pi/properties/temperature
Accept: application/json
</pre>
</div>
<div class="example">
<div class="example-title marker">
Response
</div>
<pre>
200 OK
{
"temperature": 21
}
</pre>
</div>
<p><strong>Example: Set a property</strong></p>
<div class="example">
<div class="example-title marker">
Request
</div>
<pre>
PUT http://mythingserver.com/things/pi/properties/led
{
"led": true
}
Accept: application/json
</pre>
</div>
<div class="example">
<div class="example-title marker">
Response
</div>
<pre>
200 OK
{
"led": true
}
</pre>
</div>
</section>
<section>
<h3><code>Actions</code> resource</h3>
<p>
An actions resource represents a queue of actions to be executed on a device. A new action is created in the queue with an HTTP POST request and a list of action requests in the queue can be requested with an HTTP GET request.
</p>
<p>
The URL of an actions resource can be defined by an <code>actions</code> link relation in the <a href="#links-member"><code>links</code> member</a> of a Thing Description.
</p>
<p>Any action supported by the thing can be requested via this top level action queue. If an unsupported action type is requested, the server should respond with a <code>400 Bad Request</code> response.</p>
<p><strong>Action Request</strong></p>
<pre class="example" title="Request an action">
POST https://mythingserver.com/things/lamp/actions/
Accept: application/json
{
"fade": {
"input": {
"level": 50,
"duration": 2000
}
}
}
</pre>
<pre class="example" title="Response to creating an action request">
201 Created
{
"fade": {
"input": {
"level": 50,
"duration": 2000
},
"href": "/things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655",
"status": "pending"
}
}
</pre>
<p><strong>Actions Queue</strong></p>
<pre class="example" title="Get a list of all action requests">
GET /things/lamp/actions
Accept: application/json
</pre>
<pre class="example" title="Action list response">
200 OK
[
{
"fade": {
"input": {
"level": 50,
"duration": 2000
},
"href": "/things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655",
"timeRequested": "2017-01-25T15:01:35+00:00",
"status": "pending"
}
},
{
"reboot": {
"href": "/things/lamp/actions/reboot/124e4568-f89b-22d3-a356-427656",
"timeRequested": "2017-01-24T13:13:33+00:00",
"timeCompleted": "2017-01-24T13:15:01+00:00",
"status": "completed"
}
}
]
</pre>
</section>
<section>
<h3><code>Action</code> resource</h3>
<p>An action resource represents a queue of actions of a single action type. A new action is created in the queue with an HTTP POST request and a list of action requests in the queue can be requested with an HTTP GET request.</p>
<p>The URL of an Action resource can be defined by the <code>links</code> section of an <a href="#action-object">Action object</a> in a Thing Description.</p>
<p>If a client tries to request an action of another type via this resource, the server should respond with a <code>400 Bad Request</code> response.</p>
<p><strong>Action Request</strong></p>
<pre class="example" title="Request an action">
POST https://mythingserver.com/things/lamp/actions/fade
Accept: application/json
{
"fade": {
"input": {
"level": 50,
"duration": 2000
}
}
}
</pre>
<pre class="example" title="Response to creating an action request">
201 Created
{
"fade": {
"input": {
"level": 50,
"duration": 2000
},
"href": "/things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655"
"status": "pending"
}
}
</pre>
<p><strong>Action Queue</strong></p>
<pre class="example" title="Get a list of all action requests for a given action">
GET /things/lamp/actions/fade
Accept: application/json
</pre>
<pre class="example" title="Action list response">
200 OK
[
{
"fade": {
"input": {
"level": 50,
"duration": 2000
},
"href": "/things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655",
"timeRequested": "2017-01-25T15:01:35+00:00",
"status": "pending"
}
},
{
"fade": {
"input": {
"level": 100,
"duration": 2000
},
"href": "/things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655",
"timeRequested": "2017-01-24T11:02:45+00:00",
"timeCompleted": "2017-01-24T11:02:46+00:00",
"status": "completed"
}
}
]
</pre>
</section>
<section>
<h3><code>ActionRequest</code> resource</h3>
<p>
An action request resource represents an individual action request for a given action. The current status of an action request can be retrieved with an HTTP GET request, updated with an HTTP PUT request and deleted with an HTTP
DELETE request.
</p>
<p>The URL of an Action request resource can be defined by the <code>href</code> member of an action request object in an action queue.</p>
<p><strong>Action Request Status</strong></p>
<pre class="example" title="Get the status of an action request">
GET /things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655
Accept: application/json
</pre>
<pre class="example" title="Action request status response">
200 OK
{
"fade": {
"input": {
"level": 50,
"duration": 2000
},
"href": "/things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655",
"timeRequested": "2017-01-25T15:01:35+00:00",
"status": "pending"
}
}
</pre>
<p><strong>Cancel an Action Request</strong></p>
<pre class="example" title="Cancel an action request response">DELETE /things/lamp/actions/fade/123e4567-e89b-12d3-a456-426655</pre>
<pre class="example" title="Action cancellation response">204 No Content</pre>
</section>
<section>
<h3><code>Events</code> resource</h3>
<p>An events resource provides a log of all events recently emitted by a device. An events resource is usually read only.</p>
<p>
The URL of an Events resource can be defined by an <code>events</code> link relation in the <a href="#links-member"><code>links</code> member</a> of a Thing Description.
</p>
<p><strong>Event Log</strong></p>
<pre class="example" title="Events Request">
GET /things/lamp/events
Accept: application/json
</pre>
<pre class="example" title="Events Response">
200 OK
[
{
"overheated": {
"data": 102,
"timestamp": "2017-01-25T15:01:35+00:00"
}
},
{
"reboot": {
"timestamp": "2017-01-24T13:02:45+00:00"
}
}
]
</pre>
</section>
<section>
<h3><code>Event</code> resource</h3>
<p>An event resource provides a log of events recently emitted by a device for a particular event type. An event resource is usually read only.</p>
<p>The URL of an Event resource can be defined by the <code>links</code> section of an <a href="#event-object">Event object</a> in a Thing Description.</p>
<p><strong>Event Log</strong></p>
<pre class="example" title="Event Request">
GET /things/lamp/events/overheated
Accept: application/json
</pre>
<pre class="example" title="Event Response">
200 OK
[
{
"overheated": {
"data": 102,
"timestamp": "2017-01-25T15:01:35+00:00"
}
},
{
"overheated": {
"data": 101,
"timestamp": "2017-01-24T13:02:45+00:00"
}
}
]
</pre>
</section>
<section>
<h3><code>Things</code> resource</h3>
<p>
A things resource represents a collection of web things exposed by a particular Web of Things server. This resource is not needed for individual web things, for which the Thing Description is the entry point. It is used only by
Web of Things gateways and services which expose a directory of web things.
</p>
<p><strong>Example: Get a list of things</strong></p>
<div class="example">
<div class="example-title marker">
Request
</div>
<pre>
GET /things
Accept: application/json
</pre>
</div>
<div class="example">
<div class="example-title marker">
Response
</div>
<pre>
200 OK
[
{
"id": "https://mywebthingserver.com/things/pi",
"title": "WoT Pi",
"description": "A WoT-connected Raspberry Pi",
"properties": {
"temperature": {
"title": "Temperature",
"type": "number",
"unit": "degree celsius",
"readOnly": true,
"description": "An ambient temperature sensor",
"links": [{"href": "/things/pi/properties/temperature"}]
},
"humidity": {
"title": "Humidity",
"type": "number",
"unit": "percent",
"readOnly": true,
"links": [{"href": "/things/pi/properties/humidity"}]
},
"led": {
"title": "LED",
"type": "boolean",
"description": "A red LED",
"links": [{"href": "/things/pi/properties/led"}]
}
},
"actions": {
"reboot": {
"title": "Reboot",
"description": "Reboot the device"
}
},
"events": {
"reboot": {
"description": "Going down for reboot"
}
},
"href": "/things/pi"
}
]
</pre>
</div>
</section>
<section>
<h3>Alternative Protocol Bindings</h3>
<p>
The default protocol binding for the Web Thing REST API is HTTP(S). Bindings to alternative application protocols (e.g. CoAP) may be used, but these bindings are beyond the scope of this specification. A Web Thing API protocol
binding may also be layered on top of a non-Internet application protocol by use of a gateway.
</p>
</section>
</section>
<section>
<h2>Web Thing WebSocket API</h2>
<p>
The Web Thing WebSocket API complements the REST API to provide a realtime mechanism to make multiple requests and be notified of events as soon as they happen, by keeping a WebSocket [[!WEBSOCKETS-PROTOCOL]] open on the Web Thing.
The "webthing" WebSocket subprotocol defined here has a simple set of message types and a JSON response format consistent with the Web Thing REST API.
</p>
<section>
<h3>Protocol Handshake</h3>
<p>
To open a WebSocket on a Thing, an HTTP GET request is upgraded to a WebSocket using a standard WebSocket protocol handshake [[!WEBSOCKETS-PROTOCOL]] and the "webthing" subprotocol. The WebSocket URL for a Web Thing is specified
in the links member of the Web Thing Description.
</p>
<div class="example">
<div class="example-title marker">
Request
</div>
<pre>
GET wss://mythingserver.com/things/robot
Host: mythingserver.com
Origin: https://mythingserver.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: webthing
Sec-WebSocket-Version: 13
</pre>
</div>
<div class="example">
<div class="example-title marker">
Response
</div>
<pre>
HTTP 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: webthing
</pre>
</div>
<p>A WebSocket can be opened from a web page using the JavaScript <a href="https://www.w3.org/TR/websockets/">WebSocket API</a> which will take care of the handshake detailed above and allow messages to be sent and received.</p>
<div class="example">
<div class="example-title marker">
Example
</div>
<pre>const socket = new WebSocket('wss://mywebthingserver/things/robot', 'webthing');</pre>
</div>
</section>
<section>
<h3><code>setProperty</code> message</h3>
<p>
The <code>setProperty</code> message type is sent from a web client to a Web Thing in order to set the value of one or more of its properties. This is equivalent to a <code>PUT</code> request on a Property resource URL using the
REST API, but with the WebSocket API a property value can be changed multiple times in quick succession over an open socket and multiple properties can be set at the same time.
</p>
<div class="example">
<div class="example-title marker">
Example
</div>
<pre>
{
"messageType": "setProperty",
"data": {
"leftMotor": 100
}
}
</pre>
</div>
</section>
<section>
<h3><code>requestAction</code> message</h3>
<p>
The <code>requestAction</code> message type is sent from a web client to a Web Thing to request an action be carried out on a Web Thing. This is equivalent to a <code>POST</code> request on an Actions resource URL using the REST
API, but multiple actions can be requested at the same time or in quick succession over an open socket.
</p>
<div class="example">
<div class="example-title marker">
Example
</div>
<pre>
{
"messageType": "requestAction",
"data": {
"goForward": {},
}
}
</pre>
</div>
</section>
<section>
<h3><code>addEventSubscription</code> message</h3>
<p>
The <code>addEventSubscription</code> message type is sent from a web client to a Web Thing to allow a client to subscribe to a particular event type, defined by the <code>events</code> member of a Web Thing description. This is
similar to adding an event listener in JavaScript, but events are received as an <code>event</code> message over the Web Thing WebSocket API.
</p>
<div class="example">
<div class="example-title marker">
Example
</div>
<pre>
{
"messageType": "addEventSubscription",
"data": {
"motion": {}
}
}
</pre>
</div>
</section>
<section>
<h3><code>propertyStatus</code> message</h3>
<p>
The <code>propertyStatus</code> message type is sent from a Web Thing to a web client whenever a property of a Web Thing changes. The payload data of this message is in the same format as a response to a <code>GET</code> request
on Property resource using the REST API, but the message is pushed to the client whenever a property changes and can include multiple properties at the same time.
</p>
<div class="example">
<div class="example-title marker">
Example
</div>
<pre>
{
"messageType": "propertyStatus",
"data": {
"led": true
}
}
</pre>
</div>
</section>
<section>
<h3><code>actionStatus</code> message</h3>
<p>
The <code>actionStatus</code> message type is sent from a Web Thing to a web client when the status of a requested action changes. The payload data is consistent with the format of an Action resource in the REST API, but messages
are pushed to the client as soon as the status of an action changes.
</p>