MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / request

Function request

apps/vis/web/src/api.ts:63–80  ·  view source on GitHub ↗
(path: string, method: 'GET' | 'POST' | 'DELETE')

Source from the content-addressed store, hash-verified

61}
62
63async function request<T>(path: string, method: 'GET' | 'POST' | 'DELETE'): Promise<T> {
64 const headers: Record<string, string> = { accept: 'application/json' };
65 const token = authToken();
66 if (token !== null && token.length > 0) {
67 headers['authorization'] = `Bearer ${token}`;
68 }
69 const res = await fetch(path, { method, headers });
70 if (!res.ok) {
71 let err: ApiError | null = null;
72 try {
73 err = (await res.json()) as ApiError;
74 } catch {
75 /* ignore */
76 }
77 throw new Error(err?.error ?? `HTTP ${res.status} ${res.statusText}`);
78 }
79 return (await res.json()) as T;
80}
81
82function get<T>(path: string): Promise<T> {
83 return request<T>(path, 'GET');

Callers 5

getFunction · 0.70
postFunction · 0.70
delFunction · 0.70
resolveAuthMethod · 0.50
resolveAuthMethod · 0.50

Calls 2

authTokenFunction · 0.85
jsonMethod · 0.80

Tested by

no test coverage detected