MCPcopy Create free account
hub / github.com/ShipSecAI/studio / apiRequest

Function apiRequest

frontend/src/store/mcpServerStore.ts:102–126  ·  view source on GitHub ↗
(path: string, options: RequestInit = {})

Source from the content-addressed store, hash-verified

100
101// API helpers
102async function apiRequest<T>(path: string, options: RequestInit = {}): Promise<T> {
103 const headers = await getApiAuthHeaders();
104 const { signal, ...restOptions } = options;
105 const response = await fetch(`${API_BASE_URL}${path}`, {
106 ...restOptions,
107 signal,
108 headers: {
109 ...headers,
110 'Content-Type': 'application/json',
111 ...options.headers,
112 },
113 });
114
115 if (!response.ok) {
116 const error = await response.json().catch(() => ({ message: 'Request failed' }));
117 throw new Error(error.message || `Request failed: ${response.status}`);
118 }
119
120 // Handle 204 No Content
121 if (response.status === 204) {
122 return undefined as T;
123 }
124
125 return response.json();
126}
127
128export const useMcpServerStore = create<McpServerStore>((set, get) => ({
129 ...createInitialState(),

Callers 1

mcpServerStore.tsFile · 0.85

Calls 2

getApiAuthHeadersFunction · 0.90
fetchFunction · 0.85

Tested by

no test coverage detected