MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / request

Method request

frontend/src/lib/api/apiClient.ts:104–138  ·  view source on GitHub ↗
(
    endpoint: string,
    options: RequestOptions = {}
  )

Source from the content-addressed store, hash-verified

102 }
103
104 async request<T>(
105 endpoint: string,
106 options: RequestOptions = {}
107 ): Promise<T> {
108 const { skipAuth = false, headers = {}, ...restOptions } = options;
109
110 const authHeaders = skipAuth ? {} : await this.getAuthHeaders();
111
112 const finalHeaders = {
113 'Content-Type': 'application/json',
114 ...authHeaders,
115 ...headers,
116 };
117
118 const url = `${this.baseURL}${endpoint}`;
119 const method = restOptions.method || 'GET';
120
121 // Log API call in development
122 logApiCall(method, url, restOptions.body ? JSON.parse(restOptions.body as string) : undefined);
123
124 try {
125 const response = await fetch(url, {
126 ...restOptions,
127 headers: finalHeaders,
128 credentials: 'include', // Important: Include cookies in requests
129 });
130
131 const result = await this.handleResponse<T>(response, { endpoint, options });
132 logApiResponse(url, result);
133 return result;
134 } catch (error) {
135 logApiResponse(url, null, error);
136 throw error;
137 }
138 }
139
140 async get<T>(endpoint: string, options?: RequestOptions): Promise<T> {
141 return this.request<T>(endpoint, { ...options, method: 'GET' });

Callers 6

handleResponseMethod · 0.95
getMethod · 0.95
postMethod · 0.95
putMethod · 0.95
patchMethod · 0.95
deleteMethod · 0.95

Calls 4

getAuthHeadersMethod · 0.95
logApiCallFunction · 0.90
logApiResponseFunction · 0.90
fetchFunction · 0.85

Tested by

no test coverage detected