MCPcopy Create free account
hub / github.com/cloudflare/moltworker / apiRequest

Function apiRequest

src/client/api.ts:65–86  ·  view source on GitHub ↗
(path: string, options: globalThis.RequestInit = {})

Source from the content-addressed store, hash-verified

63}
64
65async function apiRequest<T>(path: string, options: globalThis.RequestInit = {}): Promise<T> {
66 const response = await fetch(`${API_BASE}${path}`, {
67 ...options,
68 credentials: 'include',
69 headers: {
70 'Content-Type': 'application/json',
71 ...options.headers,
72 },
73 } as globalThis.RequestInit);
74
75 if (response.status === 401) {
76 throw new AuthError('Unauthorized - please log in via Cloudflare Access');
77 }
78
79 const data = (await response.json()) as T & { error?: string };
80
81 if (!response.ok) {
82 throw new Error(data.error || `API error: ${response.status}`);
83 }
84
85 return data;
86}
87
88export async function listDevices(): Promise<DeviceListResponse> {
89 return apiRequest<DeviceListResponse>('/devices');

Callers 6

listDevicesFunction · 0.85
approveDeviceFunction · 0.85
approveAllDevicesFunction · 0.85
restartGatewayFunction · 0.85
getStorageStatusFunction · 0.85
triggerSyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected