MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / request

Function request

e2e/scenarios/custom-tools.test.ts:158–177  ·  view source on GitHub ↗
(
  target: TargetShape,
  identity: Identity,
  path: string,
  init: RequestInit = {},
  expectedStatus = 200,
)

Source from the content-addressed store, hash-verified

156};
157
158const request = async <T>(
159 target: TargetShape,
160 identity: Identity,
161 path: string,
162 init: RequestInit = {},
163 expectedStatus = 200,
164): Promise<{ readonly body: T; readonly text: string }> => {
165 const headers = new Headers(init.headers);
166 headers.set("origin", new URL(target.baseUrl).origin);
167 for (const [name, value] of Object.entries(await authHeaders(target, identity))) {
168 headers.set(name, value);
169 }
170 if (init.body !== undefined && !headers.has("content-type")) {
171 headers.set("content-type", "application/json");
172 }
173 const response = await fetch(new URL(path, target.baseUrl), { ...init, headers });
174 const text = await response.text();
175 expect(response.status, `${init.method ?? "GET"} ${path}: ${text}`).toBe(expectedStatus);
176 return { body: (text.length > 0 ? JSON.parse(text) : null) as T, text };
177};
178
179const postJson = <T>(
180 target: TargetShape,

Callers 3

postJsonFunction · 0.70
deletePathFunction · 0.70

Calls 4

authHeadersFunction · 0.85
setMethod · 0.80
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected