MCPcopy
hub / github.com/21st-dev/magic-mcp / createMethod

Function createMethod

src/utils/http-client.ts:40–64  ·  view source on GitHub ↗
(method: HttpMethod)

Source from the content-addressed store, hash-verified

38}
39
40const createMethod = (method: HttpMethod) => {
41 return async <T>(
42 endpoint: string,
43 data?: unknown,
44 options: RequestInit = {}
45 ) => {
46 const headers: HeadersInit = {
47 "Content-Type": "application/json",
48 ...(TWENTY_FIRST_API_KEY ? { "x-api-key": TWENTY_FIRST_API_KEY } : {}),
49 ...options.headers,
50 };
51
52 console.log("BASE_URL", BASE_URL);
53
54 const response = await fetch(`${BASE_URL}${endpoint}`, {
55 ...options,
56 method,
57 headers,
58 ...(data ? { body: JSON.stringify(data) } : {}),
59 });
60
61 console.log("response", response);
62 return { status: response.status, data: (await response.json()) as T };
63 };
64};
65
66export const twentyFirstClient: HttpClient = {
67 get: createMethod("GET"),

Callers 1

http-client.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected