YumaPro RESTCONF server supports notifications and populates a stream resource for each notification delivery service access point. A RESTCONF client can retrieve the list of supported event streams from a RESTCONF server using the GET operation on the streams list.


RESTCONF clients can determine the URL for the subscription resource (to receive notifications) by sending an HTTP GET request for the "location" leaf with the "stream" list entry. The value returned by the server can be used for the actual notification subscription.


The client will send an HTTP GET request for the URL returned by the server with the "Accept" type "text/event-stream".

The server will treat the connection as an event stream, using the Server-Sent Events [W3C.REC-eventsource-20150203] transport strategy.


A RESTCONF client can retrieve the list of supported event streams from a RESTCONF server using the GET method on the "stream" list. The "restconf-state/streams" container definition in the ietf-restconf-monitoring YANG module is used to specify the structure and syntax of the conceptual child resources within the "streams" resource.


GET /restconf/data/ietf-restconf-monitoring:restconf-state/streams
Host: example.com
Accept: application/yang-data+json

  

The server might send the following response:


200 OK

Content-Type: application/yang-data+json
{
    "ietf-restconf-monitoring:restconf-state": {
        "capabilities": {
            "ietf-restconf-monitoring:capability": [
                "urn:ietf:params:restconf:capability:depth:1.0",
                "urn:ietf:params:restconf:capability:with-defaults:1.0",
                "urn:ietf:params:restconf:capability:defaults:1.0?basic-mode=explicit",
                "urn:ietf:params:restconf:capability:fields:1.0",
                "urn:ietf:params:restconf:capability:replay:1.0",
                "urn:ietf:params:restconf:capability:filter:1.0",
                "urn:ietf:params:restconf:capability:yang-patch:1.0"
            ]
        },
        "streams": {
            "stream": [
                {
                    "name": "RESTCONF",
                    "description": "default RESTCONF event stream",
                    "replay-support": true,
                    "replay-log-creation-time": "2017-10-05T21:18:08Z",
                    "access": [
                        {
                            "encoding": "xml",
                            "location": "http://restconf-dev/restconf/stream"
                        }
                    ]
                }
            ]
        }
    }
}


The value returned by the server for the events leaf can be used for the actual notification subscription.

The client will send an HTTP GET request for the URL returned by the server with the "Accept" type "text/event-stream".


The server will treat the connection as an event stream, using the Server Sent Events [W3C.CR-eventsource-20121211] transport strategy.


Example:

The client might send the following request to enable SSE event notification stream:

 

GET http://restconf-dev/restconf/stream HTTP/1.1
Host: example.com
Accept: text/event-stream
Cache-Control: no-cache
Connection: keep-alive

 

An example SSE event notification encoded using XML:

 

data: 
data:   <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
data:     <eventTime>2016-04-21T17:34:26Z</eventTime>
data:     <netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications">
data:       <changed-by>
data:         <username>restconf</username>
data:         <session-id>19</session-id>
data:         <source-host>127.0.0.1</source-host>
data:       </changed-by>
data:       <datastore>running</datastore>
data:       <edit>
data:         <target
data:           xmlns:t="http://netconfcentral.org/ns/test">/t:uint32.1</target>
data:         <operation>delete</operation>
data:       </edit>
data:     </netconf-config-change>
data:   </notification>

 

The server supports query parameters for a GET method on this resource. These parameters are specific to each event stream.


For more details refer to the RFC8040.



Using CURL tool, to Receive RESTCONF Notifications subscribe to event stream by GET request as follows:


> curl http://restconf-dev/restconf/stream -H "Accept:text/event-stream"


data: 
data:   <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
data:     <eventTime>2016-04-21T21:04:51Z</eventTime>
data:     <netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications">
data:       <changed-by>
data:         <username>yumaworks</username>
data:         <session-id>4</session-id>
data:         <source-host>127.0.0.1</source-host>
data:       </changed-by>
data:       <datastore>running</datastore>
data:       <edit>
data:         <target
data:           xmlns:t="http://netconfcentral.org/ns/test">/t:uint32.1</target>
data:         <operation>create</operation>
data:       </edit>
data:     </netconf-config-change>
data:   </notification>