Files
fiddle/public/js/api.js
root 463b563423 Initial commit: code playground with multi-framework support
Express + SQLite backend with Monaco editor frontend.
Supports HTML/CSS/JS, TypeScript, React (JSX/TSX), Vue SFC,
and Svelte with live preview, console output, save/fork/share.

Includes CSS preprocessors (SCSS, Less), framework-specific
compilation (Babel, TypeScript, Svelte compiler), and
CDN-loaded runtime libraries for preview rendering.
2026-02-26 08:12:39 -06:00

30 lines
713 B
JavaScript

const BASE = '/api/fiddles';
async function request(url, opts = {}) {
const res = await fetch(url, {
headers: { 'Content-Type': 'application/json' },
...opts,
});
if (!res.ok) {
const err = await res.json().catch(() => ({ error: res.statusText }));
throw new Error(err.error || res.statusText);
}
return res.json();
}
export function createFiddle(data) {
return request(BASE, { method: 'POST', body: JSON.stringify(data) });
}
export function loadFiddle(id) {
return request(`${BASE}/${id}`);
}
export function updateFiddle(id, data) {
return request(`${BASE}/${id}`, { method: 'PUT', body: JSON.stringify(data) });
}
export function listFiddles() {
return request(BASE);
}