RestDataProvider
REST data provider that maps the kanban's card actions (add-card, update-card, move-card, delete-card, duplicate-card) to HTTP calls under a configurable URL root. Handles Date parsing on load and ISO-string serialization on send.
Usage
import { RestDataProvider } from "@svar-ui/react-kanban";
const provider = new RestDataProvider(url: string, config?: object);
| Parameter | Type | Description |
|---|---|---|
url | string | API root URL. Endpoints are appended as relative paths. |
config | object | Optional config forwarded to the underlying Rest base (e.g. headers). |
Wire the provider into the kanban via api.setNext(provider) inside the init callback.
REST endpoints
| Action | Method | Endpoint | Notes |
|---|---|---|---|
add-card | POST | /cards | Local id ignored; backend assigns the id |
update-card | PUT | /cards/:id | Debounced 500 ms |
move-card | PUT | /cards/:id/move | Full payload including before |
delete-card | DELETE | /cards/:id | |
duplicate-card | POST | /cards/:id/duplicate | Local id ignored; backend assigns the id |
Methods
getData(): Promise<KanbanCard[]>
Issues GET {url}/cards and runs parseCards() on the result so deadline strings become Date instances. Returns the parsed cards array.
parseCards(data: KanbanCard[]): KanbanCard[]
Converts deadline strings to Date objects in place. Call manually if you bypass getData() but still receive raw payloads.
formatDate(date: Date): string
Serializes Date values in outgoing JSON. Returns date.toISOString() by default. Override in a subclass to emit a different format (e.g. YYYY-MM-DD).
getHandlers(): ActionMap
Returns the internal action-to-REST mapping. Override in a subclass to add extra action handlers or change routing.
Example
import { useState, useEffect } from "react";
import { Kanban, Editor, RestDataProvider } from "@svar-ui/react-kanban";
const url = "https://api.example.com";
const provider = new RestDataProvider(url);
function App() {
const [api, setApi] = useState(null);
const [cards, setCards] = useState([]);
useEffect(() => {
provider.getData().then(data => {
setCards(data);
});
}, []);
const init = (api) => {
api.setNext(provider);
};
return (
<>
<Kanban ref={setApi} init={init} cards={cards} columns={columns} />
{api && <Editor api={api} />}
</>
);
}
Related
- Working with server - loading, saving, and dynamic data
- setNext - wires the provider into the event bus
- init - callback where the provider is typically attached