Debian Codegraph @

testing/web-platform/tests/tools/wave/docs/rest-api/guides/session-events.md

raw
1 # Sending and receiving session events
2
3 The session event endpoints allow to listen for events related to a specific
4 session and to send new events to all registered listeners.
5
6 See all [REST API Guides](./README.md).
7
8 ## Register for session specific events
9
10 To receive events of a session, simply perform a GET request to the desired
11 sessions event endpoint. For example, if we want to receive any events that
12 are related to the session with token `6fdbd1a0-c339-11e9-b775-6d49dd567772`:
13
14 ```
15 GET /_wave/api/sessions/6fdbd1a0-c339-11e9-b775-6d49dd567772/events
16 ```
17
18 ```json
19 {
20 "type": "status",
21 "data": "paused"
22 }
23 ```
24
25 As this endpoint makes use of the HTTP long polling, you will not immediately
26 receive a response. The connection stays open either until an event gets
27 triggered, in which case the server will respond with that events data, or
28 there is no event within the timeout, which will return an empty response.
29
30 With one request only one event can be received. To get any further events,
31 additional requests are necessary. To not miss any events, it is important to
32 perform the next request immediately after receiving a response.
33
34 ## Sending events
35
36 To create a new event, simply send a POST request containing the event data to
37 the desired sessions event endpoint. For example, if you want to trigger a new
38 event for a session with token `6fdbd1a0-c339-11e9-b775-6d49dd567772`:
39
40 ```
41 POST /_wave/api/sessions/6fdbd1a0-c339-11e9-b775-6d49dd567772/events
42 ```
43
44 ```json
45 {
46 "type": "status",
47 "data": "paused"
48 }
49 ```
50
51 This will cause any client, that currently has a connection open as described
52 in the preceding section, to receive the specified event.