BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/fable-ui/rest-driver

REST Data Source Driver

fable-ui/rest-driver
FreeUtility

Optional Fable UI data source driver for host-owned REST endpoints.

Live preview

live · rendered by the registry
Rendered by fable-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://fable-ui.shobky.com/r/rest-driver.json

Source

lib/fable-ui/drivers/rest/rest-driver.tsfable-ui.shobky.com/r/rest-driver.json · first 6 KB
1import type {
2 DataActionInput,
3 DataActionResult,
4 DataQuery,
5 DataQueryResult,
6 DataRow,
7 DataSourceContext,
8 DataSourceDriver,
9 ResourceConfig,
10 ResourceRuntime,
11} from "@/lib/fable-ui/core"
12import type { RestDriverConfig, RestListResponse, RestResourceSource } from "./rest-driver.types"
13
14function replaceTemplate(value: string, ctx: DataSourceContext) {
15 return value.replace(/\{([^}]+)\}/g, (_match, key: string) => {
16 const replacement = ctx[key]
17
18 if (replacement == null) {
19 throw new Error(`Missing REST path parameter "${key}".`)
20 }
21
22 return encodeURIComponent(String(replacement))
23 })
24}
25
26function buildUrl(path: string, baseUrl: string | undefined, ctx: DataSourceContext) {
27 const resolvedPath = replaceTemplate(path, ctx)
28
29 if (/^https?:\/\//i.test(resolvedPath)) {
30 return new URL(resolvedPath)
31 }
32
33 const base = baseUrl || (typeof window !== "undefined" ? window.location.origin : "http://localhost")
34 return new URL(resolvedPath, base)
35}
36
37function appendQuery(url: URL, query: DataQuery) {
38 if (query.cursor) {
39 url.searchParams.set("cursor", query.cursor)
40 }
41
42 if (query.pageSize) {
43 url.searchParams.set("pageSize", String(query.pageSize))
44 }
45
46 if (query.search) {
47 url.searchParams.set("search", query.search)
48 }
49
50 if (query.sort) {
51 url.searchParams.set("sort", `${query.sort.key}:${query.sort.direction}`)
52 }
53
54 for (const [key, value] of Object.entries(query.filters ?? {})) {
55 if (value == null || value === "") {
56 continue
57 }
58
59 if (Array.isArray(value)) {
60 for (const item of value) {
61 url.searchParams.append(`filter[${key}]`, String(item))
62 }
63 } else {
64 url.searchParams.set(`filter[${key}]`, String(value))
65 }
66 }
67}
68
69async function getHeaders(config: RestDriverConfig, ctx: DataSourceContext) {
70 const configuredHeaders =
71 typeof config.headers === "function" ? await config.headers(ctx) : (config.headers ?? {})
72 const token = await ctx.auth?.getAccessToken?.()
73
74 return {
75 Accept: "application/json",
76 "Content-Type": "application/json",
77 ...configuredHeaders,
78 ...(token ? { Authorization: `Bearer ${token}` } : {}),
79 }
80}
81
82async function readJsonResponse(response: Response) {
83 const text = await response.text()
84
85 if (!text) {
86 return null
87 }
88
89 try {
90 return JSON.parse(text) as unknown
91 } catch {
92 return text
93 }
94}
95
96async function assertOk(response: Response) {
97 if (response.ok) {
98 return
99 }
100
101// … truncated

What it pulls in

Other registry items

  • shobky/fable-ui/core

Files it writes

  • lib/fable-ui/drivers/rest/rest-driver.types.ts
  • lib/fable-ui/drivers/rest/rest-driver.ts
  • lib/fable-ui/drivers/rest/index.ts

Facts

Registry
fable-ui
Type
registry:lib
Access
Free
Files written
3
Licence
MIT
First indexed
2026-08-04
Last confirmed
today

Go to the source

Docs on fable-ui fable-ui.shobky.com shobky/fable-ui on GitHub Raw registry item This item as JSON

More from fable-ui

All 10 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Fable UI Corecorefable-uiUtilitiesFree2 deps · 9 files
Firebase Data Source Driverfirebase-driverfable-uiUtilitiesFree1 dep · 3 files
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex