MCPcopy Create free account
hub / github.com/CopilotKit/aimock / httpPost

Function httpPost

src/__tests__/api-conformance.test.ts:11–38  ·  view source on GitHub ↗
(
  url: string,
  body: object,
)

Source from the content-addressed store, hash-verified

9// ---------------------------------------------------------------------------
10
11async function httpPost(
12 url: string,
13 body: object,
14): Promise<{ status: number; headers: http.IncomingHttpHeaders; body: string }> {
15 return new Promise((resolve, reject) => {
16 const req = http.request(
17 url,
18 {
19 method: "POST",
20 headers: { "Content-Type": "application/json" },
21 },
22 (res) => {
23 const chunks: Buffer[] = [];
24 res.on("data", (c) => chunks.push(c));
25 res.on("end", () =>
26 resolve({
27 status: res.statusCode!,
28 headers: res.headers,
29 body: Buffer.concat(chunks).toString(),
30 }),
31 );
32 },
33 );
34 req.on("error", reject);
35 req.write(JSON.stringify(body));
36 req.end();
37 });
38}
39
40// Parse SSE events that use data-only format (OpenAI Chat Completions, Gemini)
41function parseDataOnlySSE(body: string): object[] {

Callers 1

Calls 4

resolveFunction · 0.85
onMethod · 0.80
writeMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…