MCPcopy
hub / github.com/BuilderIO/agent-native / apiFetch

Function apiFetch

templates/macros/app/lib/api.ts:4–26  ·  view source on GitHub ↗
(
  url: string,
  options?: RequestInit,
)

Source from the content-addressed store, hash-verified

2import { agentNativePath } from "@agent-native/core/client";
3
4export async function apiFetch(
5 url: string,
6 options?: RequestInit,
7): Promise<any> {
8 const res = await fetch(agentNativePath(url), {
9 ...options,
10 headers: {
11 "Content-Type": "application/json",
12 "X-Request-Source": TAB_ID,
13 ...options?.headers,
14 },
15 });
16 if (res.status === 204) return null;
17 const data = await res.json();
18 if (!res.ok) {
19 const err = new Error(data?.error || `HTTP ${res.status}`) as Error & {
20 details?: any;
21 };
22 err.details = data?.details;
23 throw err;
24 }
25 return data;
26}

Callers 3

AppLayoutFunction · 0.90
IndexPageFunction · 0.90
useNavigationSyncFunction · 0.90

Calls 2

agentNativePathFunction · 0.90
fetchFunction · 0.50

Tested by

no test coverage detected