Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
fix CURL snippet format
Browse files
components/editor/main/snippet/curl.tsx
CHANGED
@@ -34,25 +34,38 @@ export const CurlSnippet = ({
|
|
34 |
return formattedData;
|
35 |
};
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
const Dict: Record<string, any> = {
|
38 |
GET: () => {
|
39 |
const filteredEmptyParameters = removeEmptyValues(parameters ?? {});
|
|
|
40 |
|
41 |
return `curl -X ${method} "${fullpath}?${new URLSearchParams(
|
42 |
filteredEmptyParameters
|
43 |
).toString()}" \\
|
44 |
-
|
45 |
`;
|
46 |
},
|
47 |
DELETE: () => {
|
|
|
|
|
48 |
return `curl -X ${method} "${fullpath}" \\
|
49 |
-
|
50 |
-d ${JSON.stringify(body)}
|
51 |
`;
|
52 |
},
|
53 |
DEFAULT: () => {
|
|
|
|
|
54 |
return `curl -X ${method} "${fullpath}" \\
|
55 |
-
|
56 |
-d ${JSON.stringify(body)}
|
57 |
`;
|
58 |
},
|
|
|
34 |
return formattedData;
|
35 |
};
|
36 |
|
37 |
+
const formatHeaders = () => {
|
38 |
+
return headers
|
39 |
+
? Object.entries(headers)
|
40 |
+
.map(([key, value]) => `-H "${key}: ${value}"`)
|
41 |
+
.join(" \\\n ")
|
42 |
+
: "";
|
43 |
+
};
|
44 |
+
|
45 |
const Dict: Record<string, any> = {
|
46 |
GET: () => {
|
47 |
const filteredEmptyParameters = removeEmptyValues(parameters ?? {});
|
48 |
+
const headerString = formatHeaders();
|
49 |
|
50 |
return `curl -X ${method} "${fullpath}?${new URLSearchParams(
|
51 |
filteredEmptyParameters
|
52 |
).toString()}" \\
|
53 |
+
${headerString}
|
54 |
`;
|
55 |
},
|
56 |
DELETE: () => {
|
57 |
+
const headerString = formatHeaders();
|
58 |
+
|
59 |
return `curl -X ${method} "${fullpath}" \\
|
60 |
+
${headerString} \\
|
61 |
-d ${JSON.stringify(body)}
|
62 |
`;
|
63 |
},
|
64 |
DEFAULT: () => {
|
65 |
+
const headerString = formatHeaders();
|
66 |
+
|
67 |
return `curl -X ${method} "${fullpath}" \\
|
68 |
+
${headerString} \\
|
69 |
-d ${JSON.stringify(body)}
|
70 |
`;
|
71 |
},
|