Semua endpoint di bawah butuh header x-api-key: sk_xxx (dibuat lewat dashboard) kecuali disebutkan lain. Base URL = domain worker kamu.
Ada dua cara login ke API ini:
x-api-key: sk_xxx. Buat key dari tab "API Keys" di dashboard.POST /auth/login, kirim sebagai Authorization: Bearer <token>.{ "username": "admin", "password": "secret" }
→ { "token": "...", "user": { "id": 1, "username": "admin", "role": "admin" } }
| Method | Path | Keterangan |
|---|---|---|
| GET | /api/:table | List baris. Query: limit, offset, orderBy, order, kolom=nilai |
| GET | /api/:table/:id | Ambil satu baris |
| POST | /api/:table | Insert baris baru (body: JSON) |
| PUT | /api/:table/:id | Update baris (body: JSON) |
| DELETE | /api/:table/:id | Hapus baris |
| GET | /tables | List semua tabel |
| GET | /tables/:table/columns | Struktur kolom tabel |
| Method | Path | Keterangan |
|---|---|---|
| GET | /apikeys | List API key |
| POST | /apikeys | Buat API key baru: { "name": "..." } |
| DELETE | /apikeys/:id | Revoke API key |
| POST | /query | Jalankan raw SQL: { "sql": "...", "params": [] } |
| GET | /tools/stats | Jumlah baris per tabel (badge sidebar dashboard) |
| GET | /tools/db-info | Info storage D1 (page_size, page_count, used_bytes) |
| GET | /tools/tables/:table/export | Export tabel: ?format=json|csv (CSV pakai BOM UTF-8) |
| POST | /tools/import/:table | Import baris: { "rows": [...], "mode": "insert|upsert" } (upsert butuh kolom id) |
| POST | /tools/duplicate/:table/:id | Duplicate satu baris (tanpa id-nya) |
| GET | /tools/audit-logs | Audit log: ?table=&action=CREATE|UPDATE|DELETE&limit=&offset= → { "logs": [...], "total": n } |
Endpoint /tools/* khusus dashboard (butuh JWT admin) — dipakai fitur Tools & Audit di UI. Semua mutasi lewat /api/* otomatis tercatat di tabel audit_logs (lihat tab Tools & Audit).
<?php
$ch = curl_init("https://your-worker.workers.dev/api/posts");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["x-api-key: sk_xxx"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$posts = json_decode(curl_exec($ch), true);
// Insert
$ch = curl_init("https://your-worker.workers.dev/api/posts");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["x-api-key: sk_xxx", "Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(["title" => "Halo", "body" => "Isi post"]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$created = json_decode(curl_exec($ch), true);
const res = await fetch("https://your-worker.workers.dev/api/posts", {
headers: { "x-api-key": "sk_xxx" }
});
const posts = await res.json();
await fetch("https://your-worker.workers.dev/api/posts", {
method: "POST",
headers: { "x-api-key": "sk_xxx", "Content-Type": "application/json" },
body: JSON.stringify({ title: "Halo", body: "Isi post" })
});