diff --git a/index.html b/index.html index c5e9467..6ba45b3 100644 --- a/index.html +++ b/index.html @@ -2492,7 +2492,7 @@
subscribeevent
If the connection between the Consumer and Web Thing drops
- (except as a result of the unsubscribe
operation
+ (except as a result of the unsubscribeevent
operation
defined below), the Consumer MUST re-establish the connection
following the steps outlined in the Server-Sent Events specification
[[EVENTSOURCE]].
@@ -2684,13 +2684,13 @@
unsubscribeallevents
This section defines the HTTP Webhook Profile, including a Protocol Binding for observing properties and listening for events using - WebHooks. + Webhooks.
The HTTP Webhook profile MAY be used in conjunction with the
@@ -2699,8 +2699,8 @@ HTTP Webhook Profile
cancel actions.
- The HTTP Webhook profile may be used as an alternative event mechanism - to the HTTP SSE Profile. + The HTTP Webhook profile may be used as an alternative event mechanism + to the HTTP SSE Profile.
@@ -2714,19 +2714,18 @@
- Webhooks are a mechanism for Consumers to subscribe to events emitted by a Web Thing.
+ Webhooks can be used as a mechanism for Consumers to subscribe to events and observe properties of a Web Thing.
The mechanism is scalable and supports Consumers that receive events from
- multiple Things. Consumers implement a Webhook listener that is handling the event
- streams generated by Things.
+ multiple Things. Consumers implement a Webhook listener which handles events emitted by Things.
For Webhook mechanism to function, the Consumer provides a server and client behavior.
- The client behavior is used for the initial subscription operation, whereas the server behavior is used to
- accept the event streams sent by the Thing.
+ The client behavior is used for the initial subscription operation, whereas the server behavior is used to accept the events sent by the Thing.
Thus, interactions can be initiated both by the Thing and the Consumer.
A Webhook is similar to a callback mechanism in programming languages. Consumers can
+
subscribe to properties or events they are interested in by registering a listener with that endpoint.
When the event condition occurs, the WebThing
is notifying all listeners with a corresponding notification, which is transmitted over HTTP(s).
@@ -2750,81 +2749,80 @@ HTTP Webhook Profile
Introduction
Introduction
To minimize network traffic, the same Consumer SHOULD NOT perform multiple subscriptions to
the same endpoint.
The following sequence diagram illustrates the flow of messages between a Consumer and a Web Thing when subscribing to, unsubscribing from and receiving events.
- + - - + +The following example contains a snippet from a TD that illustrates how a Webhook event can be described.
- ... - - { - "events": { - "fireAlarm": { - "title": "Fire Alarm" - "description": "Critical Condition - Fire!", - "subscription": { + ... + + { + "events": { + "fireAlarm": { + "title": "Fire Alarm" + "description": "Critical Condition - Fire!", + "subscription": { + "type": "object", + "properties": { + "callbackURL": { + "type": "string", + "format": "uri", + "description": "Callback URL provided by subscriber for Webhook notifications.", + "writeOnly": true + }, + ... + } + "data": { + "type": "boolean", + "description": "true, if the alert button has been pushed, false, if the button was armed again." + }, + "dataResponse": { + "type": "string", + "description": "sprinkler status" + }, + + "cancellation": { "type": "object", "properties": { - "callbackURL": { - "type": "string", - "format": "uri", - "description": "Callback URL provided by subscriber for Webhook notifications.", - "writeOnly": true - }, - ... + "subscriptionID": { + "type": "integer", + "description": "subscription ID to cancel", + "writeOnly": true + } } - "data": { - "type": "boolean", - "description": "true, if the alert button has been pushed, false, if the button was armed again." }, - "dataResponse": { - "type": "string", - "description": "sprinkler status" - }, - - "cancellation": { - "type": "object", - "properties": { - "subscriptionID": { - "type": "integer", - "description": "subscription ID to cancel", - "writeOnly": true + "forms": [ + { + "op": "subscribeevent", + "href": "http://192.168.0.124:8080/events/fireAlarm/subscribe", + "contentType": "application/json", + "htv:methodName": "POST" + }, + { + "op": "unsubscribeevent", + "href": "http://192.168.0.124:8080/events/fireAlarm/unsubscribe", + "htv:methodName": "POST" } - } + ] }, - "forms": [ - { - "op": "subscribeevent", - "href": "http://192.168.0.124:8080/events/fireAlarm/subscribe", - "contentType": "application/json", - "htv:methodName": "POST" - }, - { - "op": "unsubscribeevent", - "href": "http://192.168.0.124:8080/events/fireAlarm/unsubscribe", - "htv:methodName": "POST" - } - ] - }, - "batteryLow": { - ... - } - } - } -+ "batteryLow": { + ... + } + } + } +
- Event notification messages MUST comply with the following data schema. +
+ Notification messages MUST comply with the following data schema.
- +TODO: Describe data and dataResponse schemas.
@@ -2870,12 +2868,302 @@
observeproperty
+ The URL of a Property
resource to be used when
+ observing the value of a property MUST be obtained from a Thing
+ Description by locating a
+
+ Form
inside the corresponding
+
+ PropertyAffordance
+ for which:
+
op
member contains the value
+ observeproperty
+ href
+ member is http
or https
+ Content-Type
header has a value of
+ application/json
+ subprotocol
member has a value of
+ webhook
+
+
+ The resolved value of the href
member MUST then be
+ used as the URL of the Property
resource.
+
+
+ In order to observe a property, a Consumer MUST
+ provide the listener URL in the request payload of the
+ observeproperty
operation of the Property
resource.
+
+ This involves the Consumer sending an HTTP request to + the Web Thing with: +
+POST
Property
resourceContent-Type
header set to application/json
+
+ The subscription payload contains the URI for the notification listener
+ in the field with the callbackURI
key.
+
+ POST /things/lamp/properties/level HTTP/1.1 + Host: mythingserver.com + Content-Type: application/json + { + callbackURI: "http://myConsumer.com/myNotificationListener" + } ++ +
+ If a Web Thing receives an HTTP request following the format + above and the Consumer has permission to observe the + corresponding property, then it MUST send a notification + to the Consumer each time the value of the specified property changes. +
+ ++ This involves the Web Thing initially sending an HTTP + response to the Consumer with: +
+201 Created
Content-Type
header set to
+ application/json
+ Location
header set to the URL of the Event
resource
+ followed by a unique subscriptionId
+ + HTTP/1.1 201 Created + Content-Type: application/json + Location: /things/properties/level/1234-4544-1211 ++
+ Whenever a change of the property occurs, the Web Thing MUST
+ send the new value to the Consumer with an HTTP POST
request with a
+ Content-Type
header set to application/json
,
+ in the payload format defined in section
+ ["#http-webhook-profile-protocol-binding-notification-format"].
+
unobserveproperty
+
+ In order to stop observing a property, a Consumer MUST terminate
+ the corresponding subscription with the Web Thing using the
+ unobserveproperty
operation of the Property
resource.
+
+
+ This involves the Consumer sending an HTTP request to + the Web Thing with: +
+DELETE
subscription URL
+ provided in the Location
header
+ of the response to the subscribe
request
+ If a Web Thing receives an HTTP request following the format
+ above and the Consumer has subscribed to the
+ corresponding property with the subscriptionID
provided,
+ then the subscription is cancelled.
+
subscribeevent
+ This involves the Web Thing sending an HTTP + response to the Consumer with: +
+204 No Content
+ HTTP/1.1 204 No Content ++
observeallproperties
+ The URL of a Properties
resource to be used when observing
+ changes to all properties of a Web Thing MUST be obtained from a
+ Thing Description by locating a
+
+ Form
inside the top level
+ forms
+ member of a Thing Description for which:
+
op
member contains the value
+ observeallproperties
+ href
+ member is http
or https
+ Content-Type
header has a value of
+ application/json
+ subprotocol
member has a value of
+ webhook
+
+
+ The resolved value of the href
member MUST then be
+ used as the URL of the properties resource.
+
+ + In order to observe changes to all properties of a Web Thing, a + Consumer MUST send an HTTP request to the Web Thing with: +
+POST
Content-Type
header set to application/json
+ Request Payload
contains a JSON
+ object with a subscription request payload.
+ + POST /things/lamp/properties HTTP/1.1 + Host: mythingserver.com + Content-Type: application/json + + { + callbackURI: "http://myConsumer.com/myNotificationListener" + } ++ +
+ If a Web Thing receives an HTTP request following the format + above, then it MUST send notification + to the Consumer for all properties for which it has permission to subscribe. +
++ This involves the Web Thing initially sending an HTTP + response to the Consumer with: +
+201 Created
Content-Type
header set to
+ application/json
+ Location
header set to the URL of the Property
resource
+ followed by a unique subscriptionId
+ + HTTP/1.1 201 Created + Content-Type: application/json + Location: /things/lamp/properties/1234-4544-1211 ++ +
+ Whenever a property changes while a Consumer is oberving Properties,
+ the Web Thing MUST send the new value to the Consumer with an
+ HTTP POST
request with a
+ Content-Type
header set to application/json
,
+ and the payload format defined in section
+ ["#http-webhook-profile-protocol-binding-notification-format"].
+
unobserveallproperties
+ +
+ In order to unobserve all properties, a Consumer MUST invoke the
+ unobserveallproperties
operation of the Property
resource.
+
+ This involves the Consumer sending an HTTP request to + the Web Thing with: +
+DELETE
subscription URL
+ provided in the Location
header
+ of the response to the subscribeallevents
request.
+ + DELETE /things/lamp/properties/1234-4544-1211 HTTP/1.1 + Host: mythingserver.com ++ +
+ This involves the Web Thing sending an HTTP + response to the Consumer with: +
+204 No Content
+ HTTP/1.1 204 No Content ++
subscribeevent
The URL of an Event
resource to be used when
@@ -2897,6 +3185,9 @@
subscribeevent
href
member is http
or https
+ Content-Type
header has a value of
+ application/json
+ subprotocol
member has a value of
webhook
subscribeevent
POST
Event
resourceAccept
header set to application/json
+ Content-type
header set to application/json
subscribeevent
callbackURI
key.
-
POST /things/lamp/events/overheated HTTP/1.1 Host: mythingserver.com Content-Type: application/json - Accept: application/json { callbackURI: "http://myConsumer.com/myEventListener" - } + }
@@ -2952,38 +3241,34 @@
response to the Consumer with:
subscribeevent
200
201 Created
Content-Type
header set to
application/json
Accept
header set to application/json
+ Location
header set to the URL of the Event
resource
+ followed by a unique subscriptionId
- HTTP/1.1 200 OK - Content-Type: application/json - { - subscriptionId: 1234-4544-1211 - } - -+ HTTP/1.1 201 Created + Location: /things/lamp/events/overheated/1234-4544-1211 +
Whenever an event of the specified type occurs, the Web Thing MUST send event data to the Consumer using the event payload format defined in section - ["#sec-http-webhook-profile-protocol-binding-events-notification"]. + ["#sec-http-webhook-profile-protocol-binding-notification"].
-unsubscribeevent
+
In order to unsubscribe to an event, a Consumer MUST
- provide the subscriptionID
in the data payload of the
- unsubscribe
operation of the Event
resource.
+ terminate the corresponding subscription with the Web Thing using the
+ unsubscribeevent
operation of the Event
resource.
This involves the Consumer sending an HTTP request to @@ -2991,12 +3276,25 @@
unsubscribeevent
DELETE
Event
resource followed by the subscriptionId
of a valid subscriptionAccept
header set to application/json
- subscription URL
+ provided in the Location
header
+ of the response to the subscribe
request
+ If a Web Thing receives an HTTP request following the format
+ above and the Consumer has subscribed to the
+ corresponding event with the subscriptionID
provided,
+ then the subscription is cancelled.
+
+ This involves the Web Thing sending an HTTP + response to the Consumer with: +
+204 No Content
DELETE /things/lamp/events/overheated/1234-4544-1211 HTTP/1.1 Host: mythingserver.com @@ -3026,6 +3324,9 @@scheme [[RFC3986]] of the value of its
subscribeallevents
href
member ishttp
orhttps
+
Content-Type
header has a value of
+ application/json
+ subprotocol
member has a value of
webhook
subscribeallevents
POST
Accept
header set to application/json
+ Content-Type
header set to application/json
Request Payload
contains a JSON
@@ -3055,7 +3356,7 @@ subscribeallevents
POST /things/lamp/events HTTP/1.1 Host: mythingserver.com - Accept: application/json + Content-Type: application/json { callbackURI: "http://myConsumer.com/myEventListener" @@ -3073,29 +3374,26 @@response to the Consumer with:
subscribeallevents
200
201 Created
Content-Type
header set to
application/json
Accept
header set to application/json
+ Location
header set to the URL of the Event
resource
+ followed by a unique subscriptionId
subscriptionId
.- HTTP/1.1 200 OK - Content-Type: application/json - { - subscriptionId: 1234-4544-1211 - } + HTTP/1.1 201 Created + Content-Type: application/json + Location: /things/lamp/events/overheated/1234-4544-1211
Whenever an event occurs, the Web Thing MUST send event data to the Consumer using the event payload format defined in section Message Format. + href="sec-http-webhook-profile-notification-format">Notification Format.
If the connection between the Web Thing and the Consumer drops,
@@ -3113,25 +3411,43 @@
In order to unsubscribe from all events, a Consumer MUST invoke the
- subscribeallevents
unsubscribeallevents
unsubscribe
operation of the Event
resource.
+ unsubscribeevent
operation of the Event
resource.
+ If a Web Thing receives an HTTP request following the format
+ above and the Consumer has subscribed to the
+ corresponding event with the subscriptionID
provided,
+ then the subscription is cancelled.
+
This involves the Consumer sending an HTTP request to the Web Thing with:
DELETE
Event
resourceAccept
header set to application/json
- subscription URL
+ provided in the Location
header
+ of the response to the subscribeallevents
request.DELETE /things/lamp/events HTTP/1.1 Host: mythingserver.com+ +
+ This involves the Web Thing sending an HTTP + response to the Consumer with: +
+204 No Content
+ DELETE /things/lamp/events/1234-4544-1211 HTTP/1.1 + Host: mythingserver.com ++