51 lines
2.3 KiB
Markdown
51 lines
2.3 KiB
Markdown
# Data API Demo — Hypercore, Hyperbee, Hyperdrive, Autobase, Hyperdb
|
|
|
|
## What this example does
|
|
|
|
Uses the native host Data API via `BridgeSwarm.request(type, payload)`: Hypercore (info, append, get), Hyperbee (put/get/del), Hyperdrive (put/get/list), Autobase (append, info, view), and Hyperdb (insert/get/delete/find/flush on the `records` collection). Single tab; no P2P connections required for basic operations.
|
|
|
|
## Prerequisites
|
|
|
|
Install the [BridgeSwarm extension and native host](../../README.md#easy-install-recommended) before opening this example.
|
|
|
|
## How to run
|
|
|
|
**Recommended:** Extension Settings → enable **Examples server**, then open the demo URL below.
|
|
|
|
Dev alternative from the repo root:
|
|
|
|
```bash
|
|
npm run examples
|
|
```
|
|
|
|
Open **http://127.0.0.1:4173/data-demo/**. Do not use `file://`.
|
|
|
|
## Usage
|
|
|
|
1. Open the page; the log shows “Data API ready” when the extension is available.
|
|
2. Use the buttons to run each command: **Core info**, **Append**; **Put** / **Get** / **Del** for Hyperbee; **Put** / **Get** / **List /** for Hyperdrive; **Append** / **Info** / **Read view (0..4)** for Autobase; **Put** / **Get** / **Del** / **Find all** / **Flush** for Hyperdb (records).
|
|
3. The log shows request results and errors.
|
|
|
|
## Files in this directory
|
|
|
|
- **index.html** — Page structure (sections and buttons per API, log).
|
|
- **style.css** — Layout and theme (sections, rows, log).
|
|
- **app.js** — BridgeSwarm.ready(), BridgeSwarm.request() for each command type, log output.
|
|
|
|
## APIs and concepts
|
|
|
|
- `BridgeSwarm.ready()` — Wait for the injected API.
|
|
- `BridgeSwarm.request(type, payload)` — Send a command to the host. Types used:
|
|
- **Hypercore:** `coreInfo`, `coreAppend`, `coreGet`, `coreHas`, `coreUpdate`
|
|
- **Hyperbee:** `beeGet`, `beePut`, `beeDel`, `beeList`, `beePeek`
|
|
- **Hyperdrive:** `driveGet`, `drivePut`, `driveList`, `driveEntry`, `driveInfo`
|
|
- **Autobase:** `autobaseAppend`, `autobaseInfo`, `autobaseViewGet`
|
|
- **Hyperdb:** `hyperdbInsert`, `hyperdbGet`, `hyperdbDelete`, `hyperdbFindToArray`, `hyperdbFlush` (collection `records`)
|
|
|
|
Responses are `{ ok, ... }` or `{ ok: false, error }`; binary data is base64 in payloads.
|
|
|
|
## See also
|
|
|
|
- [Data API reference](../../docs/DATA-API.md) — Full command list and examples.
|
|
- [API reference](../../docs/API-REFERENCE.md) — Host request types and events.
|