You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/product/apis-integrations/rest-api.mdx
+75-48Lines changed: 75 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,16 @@ REST API also provides endpoints for [GraphQL API][ref-graphql-api] and
33
33
[Orchestration API][ref-orchestration-api]. However, they target specific use
34
34
cases and are not considered part of the REST API.
35
35
36
-
## Example request
36
+
## Transport
37
+
38
+
The REST API supports the following transports:
39
+
40
+
| Transport | Description | When to use |
41
+
| --- | --- | --- |
42
+
| HTTP | HTTP-based protocol with long polling | Use by default |
43
+
| WebSocket |[WebSocket][link-websocket]-based protocol with support for real-time updates | Use for applications that require subscriptions to real-time updates |
44
+
45
+
### HTTP transport
37
46
38
47
You can use the `curl` utility to execute requests to the REST API:
39
48
@@ -88,6 +97,36 @@ curl \
88
97
http://localhost:4000/cubejs-api/v1/meta | jq
89
98
```
90
99
100
+
You can also use the [JavaScript SDK][ref-javascript-sdk] to call the REST API
101
+
from your JavaScript applications.
102
+
103
+
### WebSocket transport
104
+
105
+
WebSocket can be used to provide real-time experience. You can configire it via the
106
+
`CUBEJS_WEB_SOCKETS` environment variable.
107
+
108
+
Clients using the [JavaScript SDK][ref-javascript-sdk] can be switched to WebSocket
109
+
by passing `WebSocketTransport` to the `CubeApi` constructor:
See [this recipe][ref-recipe-real-time-data-fetch] for an example of real-time
126
+
data fetch using the WebSocket transport.
127
+
128
+
</ReferenceBox>
129
+
91
130
## Configuration
92
131
93
132
REST API is enabled by default and secured using [API scopes][self-api-scopes]
@@ -188,30 +227,7 @@ how to generate it.
188
227
In the development environment the token is not required for authorization, but
189
228
you can still use it to pass a security context.
190
229
191
-
### Continue wait
192
-
193
-
If the request takes too long to be processed, Cube Backend responds with
194
-
`{ "error": "Continue wait" }` and 200 status code. This is how the long polling
195
-
mechanism in Cube is implemented. Clients should continuously retry the same
196
-
query in a loop until they get a successful result. Subsequent calls to the Cube
197
-
endpoints are idempotent and don't lead to scheduling new database queries if
198
-
not required by the [`refresh_key`][ref-schema-ref-cube-refresh-key]. Also,
199
-
receiving `Continue wait` doesn't mean the database query has been canceled, and
200
-
it's actually still being processed by the Cube. Database queries that weren't
201
-
started and are no longer waited by the client's long polling loop will be
202
-
marked as orphaned and removed from the querying queue.
203
-
204
-
Possible reasons of **Continue wait**:
205
-
206
-
- The query requested is heavy, and it takes some time for the database to
207
-
process it. Clients should wait for its completion, continuously sending the
208
-
same REST API request. [`continueWaitTimeout`][ref-conf-queue-opts] can be
209
-
adjusted in order to change the time Cube waits before returning
210
-
`Continue wait` message.
211
-
- There are many queries requested and Cube backend queues them to save database
212
-
from overloading.
213
-
214
-
### Error Handling
230
+
### Error handling
215
231
216
232
Cube REST API has basic errors and HTTP Error codes for all requests.
217
233
@@ -222,7 +238,7 @@ Cube REST API has basic errors and HTTP Error codes for all requests.
222
238
| 403 | Invalid token | The auth token provided is not valid. It may be expired or have invalid signature. |
223
239
| 500 | Error message | Cube internal server error. Check error message for details. |
224
240
225
-
### Request Span Annotation
241
+
### Request span annotation
226
242
227
243
For monitoring tools such as Cube Cloud proper request span annotation should be
228
244
provided in `x-request-id` header of a request. Each request id should consist
@@ -232,27 +248,31 @@ should be unique for each separate request. `spanId` should define user
232
248
interaction span such us `Continue wait` retry cycle and it's value shouldn't
233
249
change during one single interaction.
234
250
235
-
### Pagination
236
-
237
-
Cube supports paginated requests for the `/v1/load` endpoint by including
238
-
[`limit` and `offset` parameters][ref-rest-query-format] in the query. For
239
-
example, the following query will retrieve rows 101-200 from the `Orders` cube:
240
-
241
-
```json
242
-
{
243
-
"dimensions": ["Orders.status"],
244
-
"measures": ["Orders.count"],
245
-
"timeDimensions": [
246
-
{
247
-
"dimension": "Orders.createdAt",
248
-
"dateRange": "last year",
249
-
"granularity": "day"
250
-
}
251
-
],
252
-
"limit": 100,
253
-
"offset": 100
254
-
}
255
-
```
251
+
## Troubleshooting
252
+
253
+
### `Continue wait`
254
+
255
+
If the request takes too long to be processed, the REST API responds with
256
+
`{ "error": "Continue wait" }` and the status code 200.
257
+
258
+
This is part of the long polling mechanism:
259
+
- After an API instance receives a request, it adds the query to the query queue.
260
+
- If the query takes too long to be processed, the API instance will respond with `Continue wait`. Receiving `Continue wait` doesn't mean the database query has been canceled, and it's actually still being processed by Cube.
261
+
- Clients who received `Continue wait` should continuously retry the same query in a loop until they get a successful result. Database queries that are no longer retried by clients will be marked as orphaned and removed from the query queue. Subsequent calls to the REST API are idempotent and don't lead to scheduling new database queries if not required by the [`refresh_key`][ref-schema-ref-cube-refresh-key].
262
+
263
+
Possible reasons of `Continue wait`:
264
+
- The query is too heavy for the upstream database, i.e., it takes too long to be processed.
265
+
- The maximum [concurrency][ref-concurrency] is reached, i.e., there are many queries
266
+
waiting in the query queue until the previous ones are completed.
267
+
268
+
[`continueWaitTimeout`][ref-conf-queue-opts] configuration option can be adjusted
269
+
in order to change the time Cube waits before returning `Continue wait` message.
270
+
However, it's recommended to address the root cause of the issue instead of
271
+
increasing the timeout:
272
+
- Switch from a [traditional database][ref-traditional-databases] to a [data
273
+
warehouse][ref-data-warehouses].
274
+
- Increase the [concurrency][ref-concurrency] if your database can handle it.
275
+
- Implement [pre-aggregations][ref-pre-aggregations] to reduce the query time by using Cube Store.
0 commit comments