Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit 403c9aa

Browse files
committed
Order instructions chronologically.
1 parent 49ed601 commit 403c9aa

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

api-websockets.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ versioned as a whole.
88
This is a _draft_ protocol.
99
This specific version is identified by the string `solid-ws-draft/v0.1.0-alpha`.
1010

11-
## Subscribing
11+
## Protocol description
1212

1313
Live updates are currently only supported through WebSockets. This describes a
1414
subscription mechanism through which clients can be notified in real time of
1515
changes affecting a given resource.
1616

17-
The PubSub system is very basic. Clients only need to open a WebSocket
18-
connection and *sub*(scribe) to a given resource URI. If any change occurs in
19-
that resource, a *pub*(lish) event will be sent to all the subscribed clients.
20-
21-
The WebSocket server URI is the same for any resource located on a given data
22-
space (same hostname). To discover the URI of the WebSocket server, clients can
23-
send an HTTP OPTIONS request. The server will then include an `Updates-Via` header in
24-
the response:
17+
### Discovery
18+
The PubSub system is very basic.
19+
First, a client needs to obtain the URI of the WebSocket.
20+
The WebSocket server URI is the same for any resource
21+
located on a given data space (same hostname).
22+
To discover the URI of the WebSocket server,
23+
clients can send an HTTP `OPTIONS` request.
24+
The server will then include an `Updates-Via` header in the response:
2525

2626
REQUEST:
2727

@@ -35,9 +35,24 @@ RESPONSE:
3535
```http
3636
HTTP/1.1 200 OK
3737
...
38-
Updates-Via: wss://example.org/
38+
Updates-Via: wss://example.org
3939
```
4040

41+
### Connection
42+
Then, the client needs to open a WebSocket connection
43+
to that URI.
44+
45+
For example, in JavaScript, this could be done as follows:
46+
47+
```
48+
const socket = new WebSocket('wss://example.org');
49+
```
50+
51+
### Subscription
52+
Then, the client needs to *sub*(scribe) to a given resource URI.
53+
If any change occurs in that resource,
54+
a *pub*(lish) event will be sent to all the subscribed clients.
55+
4156
To subscribe to a resource, clients will need to send the keyword `sub` followed
4257
by an empty space and then the URI of the resource:
4358

@@ -81,6 +96,7 @@ Then the following notification message will be sent:
8196
pub https://example.org/data/
8297
```
8398

99+
### Example
84100
Here is a Javascript example on how to subscribe to live updates for a `test`
85101
resource at `https://example.org/data/test`:
86102

0 commit comments

Comments
 (0)