Spaces:
Running
Running
| async function request(path, options = {}) { | |
| const response = await fetch(path, { | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| ...(options.headers || {}), | |
| }, | |
| ...options, | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`API ${response.status}: ${response.statusText}`); | |
| } | |
| if (response.status === 204) return null; | |
| return response.json(); | |
| } | |
| export async function loadRuns() { | |
| return request('/api/runs'); | |
| } | |
| export async function createRun(run) { | |
| return request('/api/runs', { | |
| method: 'POST', | |
| body: JSON.stringify(run), | |
| }); | |
| } | |
| export async function updateRun(id, changes) { | |
| return request(`/api/runs/${encodeURIComponent(id)}`, { | |
| method: 'PUT', | |
| body: JSON.stringify(changes), | |
| }); | |
| } | |
| export async function deleteRun(id) { | |
| return request(`/api/runs/${encodeURIComponent(id)}`, { | |
| method: 'DELETE', | |
| }); | |
| } | |