MCPcopy
hub / github.com/apache/caldera / apiV2

Function apiV2

static/js/shared.js:28–57  ·  view source on GitHub ↗
(requestType, endpoint, body = null, jsonRequest = true)

Source from the content-addressed store, hash-verified

26}
27
28function apiV2(requestType, endpoint, body = null, jsonRequest = true) {
29 let requestBody = { method: requestType };
30 if (jsonRequest) {
31 requestBody.headers = { 'Content-Type': 'application/json' };
32 if (body) {
33 requestBody.body = JSON.stringify(body);
34 }
35 } else {
36 if (body) {
37 requestBody.body = body;
38 }
39 }
40
41 return new Promise((resolve, reject) => {
42 fetch(endpoint, requestBody)
43 .then((response) => {
44 if (!response.ok) {
45 reject(response.statusText);
46 }
47 return response.text();
48 })
49 .then((text) => {
50 try {
51 resolve(JSON.parse(text));
52 } catch {
53 resolve(text);
54 }
55 });
56 });
57}
58
59/**
60 * Given list of abilities, returns list filtered by the following

Callers 2

initPageFunction · 0.85
addTabFunction · 0.85

Calls 2

resolveFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected