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

Function restRequest

static/js/shared.js:4–26  ·  view source on GitHub ↗
(requestType, data, callback = (r) => {
    console.log('Fetch Success', r);
}, endpoint = '/api/rest')

Source from the content-addressed store, hash-verified

2/* HELPFUL functions to call */
3
4function restRequest(requestType, data, callback = (r) => {
5 console.log('Fetch Success', r);
6}, endpoint = '/api/rest') {
7 const requestData = requestType === 'GET' ?
8 {method: requestType, headers: {'Content-Type': 'application/json'}} :
9 {method: requestType, headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)}
10
11 fetch(endpoint, requestData)
12 .then((response) => {
13 if (!response.ok) {
14 throw (response.statusText);
15 }
16 return response.text();
17 })
18 .then((text) => {
19 try {
20 callback(JSON.parse(text));
21 } catch {
22 callback(text);
23 }
24 })
25 .catch((error) => console.error(error));
26}
27
28function apiV2(requestType, endpoint, body = null, jsonRequest = true) {
29 let requestBody = { method: requestType };

Callers 2

addTabFunction · 0.85
downloadReportFunction · 0.85

Calls 2

logMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected