Skip to content

Commit a128322

Browse files
Merge pull request #102 from DHTMLX/sp-SVAR-2288
[add] RestDataProvider methods documentation
2 parents e367f95 + effa53e commit a128322

7 files changed

Lines changed: 239 additions & 10 deletions

File tree

docs/api/overview/internal_rest_overview.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ description: You can have an Internal RestDataProvider methods overview of JavaS
66

77
# RestDataProvider methods
88

9-
| Name | Description |
10-
| ------------------------------------------------------------ | ------------------------------------------------------------------ |
11-
| [](api/provider/rest_methods/js_kanban_getcards_method.md) | @getshort(api/provider/rest_methods/js_kanban_getcards_method.md) |
12-
| [](api/provider/rest_methods/js_kanban_getcolumns_method.md) | @getshort(api/provider/rest_methods/js_kanban_getcolumns_method.md) |
13-
| [](api/provider/rest_methods/js_kanban_getlinks_method.md) | @getshort(api/provider/rest_methods/js_kanban_getlinks_method.md) |
14-
| [](api/provider/rest_methods/js_kanban_getrows_method.md) | @getshort(api/provider/rest_methods/js_kanban_getrows_method.md) |
15-
| [](api/provider/rest_methods/js_kanban_getusers_method.md) | @getshort(api/provider/rest_methods/js_kanban_getusers_method.md) |
16-
| [](api/provider/rest_methods/js_kanban_send_method.md) | @getshort(api/provider/rest_methods/js_kanban_send_method.md) |
9+
| Name | Description |
10+
| --------------------------------------------------------------- | --------------------------------------------------------------------- |
11+
| [](api/provider/rest_methods/js_kanban_getcards_method.md) | @getshort(api/provider/rest_methods/js_kanban_getcards_method.md) |
12+
| [](api/provider/rest_methods/js_kanban_getcolumns_method.md) | @getshort(api/provider/rest_methods/js_kanban_getcolumns_method.md) |
13+
| [](api/provider/rest_methods/js_kanban_gethandlers_method.md) | @getshort(api/provider/rest_methods/js_kanban_gethandlers_method.md) |
14+
| [](api/provider/rest_methods/js_kanban_getidresolver_method.md) | @getshort(api/provider/rest_methods/js_kanban_getidresolver_method.md)|
15+
| [](api/provider/rest_methods/js_kanban_getlinks_method.md) | @getshort(api/provider/rest_methods/js_kanban_getlinks_method.md) |
16+
| [](api/provider/rest_methods/js_kanban_getqueue_method.md) | @getshort(api/provider/rest_methods/js_kanban_getqueue_method.md) |
17+
| [](api/provider/rest_methods/js_kanban_getrows_method.md) | @getshort(api/provider/rest_methods/js_kanban_getrows_method.md) |
18+
| [](api/provider/rest_methods/js_kanban_getusers_method.md) | @getshort(api/provider/rest_methods/js_kanban_getusers_method.md) |
19+
| [](api/provider/rest_methods/js_kanban_send_method.md) | @getshort(api/provider/rest_methods/js_kanban_send_method.md) |
20+
| [](api/provider/rest_methods/js_kanban_setheaders_method.md) | @getshort(api/provider/rest_methods/js_kanban_setheaders_method.md) |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
sidebar_label: getHandlers()
3+
title: getHandlers REST Method
4+
description: You can learn about the getHandlers REST method in the documentation of the DHTMLX JavaScript Kanban library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Kanban.
5+
---
6+
7+
# getHandlers()
8+
9+
### Description
10+
11+
@short: Returns the default action handlers used by RestDataProvider to send data operations to the server
12+
13+
:::info
14+
The **getHandlers()** method is a part of the **RestDataProvider** service intended for working with server.
15+
:::
16+
17+
### Usage
18+
19+
~~~jsx {}
20+
getHandlers(): object;
21+
~~~
22+
23+
### Returns
24+
25+
The `getHandlers()` method returns an object that maps the [data operations supported by `RestDataProvider`](guides/working_with_server.md/#restdataprovider) to the requests that the provider sends to the server.
26+
27+
The returned object is the default actions map used internally by `RestDataProvider`. Override this method to add custom handlers or replace the default ones with custom logic.
28+
29+
### Example
30+
31+
To extend the default handlers with custom ones, create a class that extends `RestDataProvider` and override `getHandlers()`. Always call `super.getHandlers()` from the override to keep the default handlers in place:
32+
33+
~~~jsx {3-11}
34+
const url = "https://some_backend_url";
35+
36+
class MyDataProvider extends kanban.RestDataProvider {
37+
getHandlers() {
38+
const handlers = super.getHandlers();
39+
return {
40+
...handlers,
41+
// custom or overridden handlers go here
42+
};
43+
}
44+
}
45+
46+
const restProvider = new MyDataProvider(url);
47+
board.api.setNext(restProvider);
48+
~~~
49+
50+
:::warning
51+
Do not copy the default handlers into the override manually. The contents of the default actions map may change between versions; calling `super.getHandlers()` guarantees that your custom handlers stay merged on top of the current defaults.
52+
:::
53+
54+
**Related articles:** [Working with server](guides/working_with_server.md)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
sidebar_label: getIDResolver()
3+
title: getIDResolver REST Method
4+
description: You can learn about the getIDResolver REST method in the documentation of the DHTMLX JavaScript Kanban library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Kanban.
5+
---
6+
7+
# getIDResolver()
8+
9+
### Description
10+
11+
@short: Returns a function that resolves temporary client-side IDs to backend IDs
12+
13+
:::info
14+
The `getIDResolver()` method is a part of the **RestDataProvider** service intended for working with server.
15+
:::
16+
17+
### Usage
18+
19+
~~~jsx {}
20+
getIDResolver(): (id: string | number, type: number) => string | number;
21+
~~~
22+
23+
### Returns
24+
25+
The method returns an `idResolver(id, type)` function:
26+
27+
- `id` — the entity ID to resolve (a temporary client-side ID or a regular ID)
28+
- `type` — the model type the ID belongs to:
29+
- `1` — card (`CardID`)
30+
- `2` — row (`RowID`)
31+
- `3` — column (`ColumnID`)
32+
- `4` — link (`LinkID`)
33+
- `5` — comment (`CommentID`)
34+
35+
When the client creates a new entity (card, column, row, link, comment), `RestDataProvider` assigns it a temporary client-side ID and remembers the backend ID returned by the server. The `idResolver(id, type)` function returns the backend ID for any temporary ID it still holds. For IDs that already match the backend, the function returns them unchanged.
36+
37+
### Example
38+
39+
The most common use case is wiring `RestDataProvider` to `kanbanUpdates` in a multiuser setup so that server events targeted at backend IDs apply correctly to entities that still live on the client under temporary IDs:
40+
41+
~~~jsx {6-9}
42+
const url = "https://some_backend_url";
43+
const restProvider = new kanban.RestDataProvider(url);
44+
45+
// other initialization...
46+
47+
const handlers = kanbanUpdates(
48+
board.api,
49+
restProvider.getIDResolver()
50+
);
51+
52+
const events = new kanban.RemoteEvents(url + "/api/v1", token);
53+
events.on(handlers);
54+
~~~
55+
56+
The same resolver function can be used inside custom handlers passed to `RemoteEvents.on()`. See [Customize server events](guides/working_with_server.md/#customize-server-events) for a complete example.
57+
58+
**Related articles:** [Working with server: Multiuser backend](guides/working_with_server.md/#multiuser-backend)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
sidebar_label: getQueue()
3+
title: getQueue REST Method
4+
description: You can learn about the getQueue REST method in the documentation of the DHTMLX JavaScript Kanban library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Kanban.
5+
---
6+
7+
# getQueue()
8+
9+
### Description
10+
11+
@short: Returns the internal queue of actions that RestDataProvider processes
12+
13+
:::info
14+
The `getQueue()` method is a part of the **RestDataProvider** service intended for working with server.
15+
:::
16+
17+
### Usage
18+
19+
~~~jsx {}
20+
getQueue(): object;
21+
~~~
22+
23+
### Returns
24+
25+
The method returns the internal `ActionQueue` instance used by `RestDataProvider` to process data operations sent to the server. The queue is responsible for:
26+
27+
- buffering actions until pending requests resolve
28+
- assigning temporary client-side IDs to newly created entities and replacing them with backend IDs once the server responds
29+
30+
The queue is used internally by other methods of `RestDataProvider`. The most common indirect use is via [`getIDResolver()`](api/provider/rest_methods/js_kanban_getidresolver_method.md), which is built on top of the queue's ID-resolution logic.
31+
32+
You normally do not need to call `getQueue()` directly. Use this method only when you need fine-grained access to the queue (for example, when implementing advanced custom synchronization between the client and the server).
33+
34+
**Related articles:** [Working with server](guides/working_with_server.md)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
sidebar_label: setHeaders()
3+
title: setHeaders REST Method
4+
description: You can learn about the setHeaders REST method in the documentation of the DHTMLX JavaScript Kanban library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Kanban.
5+
---
6+
7+
# setHeaders()
8+
9+
### Description
10+
11+
@short: Sets custom HTTP headers that RestDataProvider attaches to every request sent to the server
12+
13+
:::info
14+
The `setHeaders()` method is a part of the **RestDataProvider** service intended for working with server.
15+
:::
16+
17+
### Usage
18+
19+
~~~jsx {}
20+
setHeaders(headers: object): void;
21+
~~~
22+
23+
### Parameters
24+
25+
- `headers` - (required) an object whose keys are header names and values are header values. The headers are appended to the default `Content-Type: application/json` header on every request sent via [`send()`](api/provider/rest_methods/js_kanban_send_method.md).
26+
27+
### Example
28+
29+
The most common use case is attaching an authorization token to every request:
30+
31+
~~~jsx {4-6}
32+
const url = "https://some_backend_url";
33+
const restProvider = new kanban.RestDataProvider(url);
34+
35+
restProvider.setHeaders({
36+
"Remote-Token": "eyJpZCI6IjEzMzciLCJ1c2VybmFtZSI6ImJpem9uZSIsImlhdC...",
37+
});
38+
~~~
39+
40+
To set headers only for a particular request rather than for every request, pass them as the fourth argument to [`send()`](api/provider/rest_methods/js_kanban_send_method.md) instead.
41+
42+
**Related articles:** [Working with server: Multiuser backend](guides/working_with_server.md/#multiuser-backend)

docs/guides/working_with_server.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,47 @@ JavaScript Kanban includes the `RestDataProvider` service, which fully supports
3838

3939
## REST methods
4040

41-
The `RestDataProvider` service exposes the following REST methods for dynamic data loading:
41+
The `RestDataProvider` service exposes the following REST methods:
4242

4343
- [`getCards()`](api/provider/rest_methods/js_kanban_getcards_method.md) — gets a promise with cards data
4444
- [`getColumns()`](api/provider/rest_methods/js_kanban_getcolumns_method.md) — gets a promise with columns data
45+
- [`getHandlers()`](api/provider/rest_methods/js_kanban_gethandlers_method.md) — returns the default action handlers used by the provider
46+
- [`getIDResolver()`](api/provider/rest_methods/js_kanban_getidresolver_method.md) — returns a function that resolves temporary client IDs to backend IDs
4547
- [`getLinks()`](api/provider/rest_methods/js_kanban_getlinks_method.md) — gets a promise with links data
48+
- [`getQueue()`](api/provider/rest_methods/js_kanban_getqueue_method.md) — returns the internal queue of actions processed by the provider
4649
- [`getRows()`](api/provider/rest_methods/js_kanban_getrows_method.md) — gets a promise with rows data
4750
- [`getUsers()`](api/provider/rest_methods/js_kanban_getusers_method.md) — gets a promise with users data
4851
- [`send()`](api/provider/rest_methods/js_kanban_send_method.md) — sends a custom HTTP request and returns a promise
52+
- [`setHeaders()`](api/provider/rest_methods/js_kanban_setheaders_method.md) — sets custom HTTP headers attached to every request
53+
54+
## Customize RestDataProvider
55+
56+
To customize how `RestDataProvider` sends data operations to the server, extend the class and override one of its methods. Most often, customization targets the default action handlers — for example, to add a handler for a custom event or to extend the payload of an existing operation.
57+
58+
To add custom handlers without losing the default ones, override [`getHandlers()`](api/provider/rest_methods/js_kanban_gethandlers_method.md) and merge custom entries on top of `super.getHandlers()`:
59+
60+
~~~js {3-11}
61+
const url = "https://some_backend_url";
62+
63+
class MyDataProvider extends kanban.RestDataProvider {
64+
getHandlers() {
65+
const handlers = super.getHandlers();
66+
return {
67+
...handlers,
68+
// custom or overridden handlers go here
69+
};
70+
}
71+
}
72+
73+
const restProvider = new MyDataProvider(url);
74+
board.api.setNext(restProvider);
75+
~~~
76+
77+
:::warning
78+
Always call `super.getHandlers()` from the override and spread its result. Do not copy the default handlers into the override manually — the actions map may change between versions, so a hard-coded copy can silently get out of sync with the current defaults.
79+
:::
80+
81+
Another common customization target is the [`send()`](api/provider/rest_methods/js_kanban_send_method.md) method, which is called by every default handler. Override `send()` to inject extra headers, rewrite URLs, or wrap every server request with custom logic.
4982

5083
## Interact with the backend
5184

sidebars.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,14 @@ module.exports = {
324324
items: [
325325
"api/provider/rest_methods/js_kanban_getcards_method",
326326
"api/provider/rest_methods/js_kanban_getcolumns_method",
327+
"api/provider/rest_methods/js_kanban_gethandlers_method",
328+
"api/provider/rest_methods/js_kanban_getidresolver_method",
327329
"api/provider/rest_methods/js_kanban_getlinks_method",
330+
"api/provider/rest_methods/js_kanban_getqueue_method",
328331
"api/provider/rest_methods/js_kanban_getrows_method",
329332
"api/provider/rest_methods/js_kanban_getusers_method",
330-
"api/provider/rest_methods/js_kanban_send_method"
333+
"api/provider/rest_methods/js_kanban_send_method",
334+
"api/provider/rest_methods/js_kanban_setheaders_method"
331335
]
332336
}
333337
]

0 commit comments

Comments
 (0)