MCPcopy Create free account
hub / github.com/Botloader/botloader / do

Method do

frontend-common/src/api_client.ts:21–58  ·  view source on GitHub ↗
(method: string, path: string, body?: Body)

Source from the content-addressed store, hash-verified

19 }
20
21 async do<T>(method: string, path: string, body?: Body): Promise<ApiResult<T>> {
22 let base = this.base;
23
24 let headers = {};
25 if (this.token) {
26 headers = {
27 Authorization: this.token,
28 ...headers,
29 };
30 }
31
32 let sendingBody = body?.body
33 if (body && body.kind === "json") {
34 headers = {
35 "Content-Type": "application/json",
36 ...headers,
37 };
38 sendingBody = JSON.stringify(body.body)
39 }
40
41 let response = await this.fetcher.fetch(base + path, {
42 headers: headers,
43 method: method,
44 body: sendingBody,
45 });
46
47 console.log(`Response status for ${path}: ${response.status}`);
48 if (response.status === 204) {
49 return {} as ApiResult<T>;
50 }
51
52 if (response.status !== 200) {
53 let decoded: ApiErrorResponse = await response.json() as ApiErrorResponse;
54 return new ApiError(response.status, decoded);
55 }
56
57 return await response.json() as ApiResult<T>;
58 }
59
60 async get<T>(path: string,): Promise<ApiResult<T>> {
61 return await this.do("GET", path);

Callers 5

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

Calls 3

logMethod · 0.80
fetchMethod · 0.65
jsonMethod · 0.65

Tested by

no test coverage detected