Skip to content

Commit 1d7777d

Browse files
committed
docs: Add a usage example for WebSocket transport
1 parent 5df4280 commit 1d7777d

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

docs/pages/product/apis-integrations/rest-api.mdx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ The REST API supports the following transports:
4444

4545
### HTTP transport
4646

47-
You can use the `curl` utility to execute requests to the REST API:
47+
You can use the `curl` utility to execute requests to the REST API. Provide the [API
48+
token](#authentication) in the `Authorization` header:
4849

4950
```bash
5051
curl \
51-
-H "Authorization: JSON.WEB.TOKEN" \
52+
-H "Authorization: TOKEN" \
5253
-G \
5354
--data-urlencode 'query={
5455
"dimensions": [
@@ -82,7 +83,7 @@ from the REST API in your terminal:
8283

8384
```bash
8485
curl \
85-
-H "Authorization: JSON.WEB.TOKEN" \
86+
-H "Authorization: TOKEN" \
8687
-G \
8788
--data-urlencode 'query={"measures": ["orders.count"]}' \
8889
http://localhost:4000/cubejs-api/v1/load | jq .data
@@ -93,7 +94,7 @@ endpoint][ref-ref-meta-endpoint]:
9394

9495
```bash
9596
curl \
96-
-H "Authorization: JSON.WEB.TOKEN" \
97+
-H "Authorization: TOKEN" \
9798
http://localhost:4000/cubejs-api/v1/meta | jq
9899
```
99100

@@ -102,8 +103,27 @@ from your JavaScript applications.
102103

103104
### WebSocket transport
104105

105-
WebSocket can be used to provide real-time experience. You can configire it via the
106-
`CUBEJS_WEB_SOCKETS` environment variable.
106+
WebSocket transport can be used to provide real-time experience. You can configure it via
107+
the `CUBEJS_WEB_SOCKETS` environment variable.
108+
109+
You can use the [`websocat` utility][link-websocat] to test the WebSocket transport:
110+
111+
```bash
112+
websocat ws://localhost:4000/cubejs-api/v1/ws --text
113+
```
114+
115+
After connecting, send the [API token](#authentication) as the first message:
116+
117+
```json
118+
{"authorization":"TOKEN"}
119+
```
120+
121+
Then, send requests. Each request should include a distinct `messageId`, the desired API
122+
endpoint in `method`, and additional `params`:
123+
124+
```json
125+
{"messageId":"1","method":"load","params":{"query":{"measures":["orders.count"]}}}
126+
```
107127

108128
Clients using the [JavaScript SDK][ref-javascript-sdk] can be switched to WebSocket
109129
by passing `WebSocketTransport` to the `CubeApi` constructor:
@@ -114,7 +134,7 @@ import WebSocketTransport from "@cubejs-client/ws-transport"
114134

115135
const cubeApi = cube({
116136
transport: new WebSocketTransport({
117-
authorization: CUBE_TOKEN,
137+
authorization: TOKEN,
118138
apiUrl: "ws://localhost:4000/"
119139
})
120140
})
@@ -326,4 +346,5 @@ warehouse][ref-data-warehouses].
326346
[ref-pre-aggregations]: /product/caching/using-pre-aggregations
327347
[ref-javascript-sdk]: /product/apis-integrations/javascript-sdk
328348
[ref-recipe-real-time-data-fetch]: /product/apis-integrations/recipes/real-time-data-fetch
329-
[ref-refresh-keys]: /product/data-modeling/reference/cube#refresh_key
349+
[ref-refresh-keys]: /product/data-modeling/reference/cube#refresh_key
350+
[link-websocat]: https://github.com/vi/websocat

docs/pages/product/configuration/reference/environment-variables.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ If `true`, then use WebSocket for data fetching.
14731473

14741474
| Possible Values | Default in Development | Default in Production |
14751475
| --------------- | ---------------------- | --------------------- |
1476-
| `true`, `false` | `true` | `true` |
1476+
| `true`, `false` | `false` | `false` |
14771477

14781478
## `CUBEJS_TESSERACT_ORCHESTRATOR`
14791479

0 commit comments

Comments
 (0)