|
|
@@ -1,8 +1,14 @@
|
|
|
-import { Fence } from "@/components/Fence";
|
|
|
-
|
|
|
-
|
|
|
-const JavaScriptRequestRenderer = ({ url, headers, bodyMethod, rpcVersion, bodyParams, id }) => {
|
|
|
- const httpBody = bodyParams;
|
|
|
+import { Fence } from '@/components/Fence'
|
|
|
+
|
|
|
+const JavaScriptRequestRenderer = ({
|
|
|
+ url,
|
|
|
+ headers,
|
|
|
+ bodyMethod,
|
|
|
+ rpcVersion,
|
|
|
+ bodyParams,
|
|
|
+ id,
|
|
|
+}) => {
|
|
|
+ const httpBody = bodyParams
|
|
|
|
|
|
const object = {
|
|
|
method: 'POST',
|
|
|
@@ -13,15 +19,15 @@ const JavaScriptRequestRenderer = ({ url, headers, bodyMethod, rpcVersion, bodyP
|
|
|
method: bodyMethod,
|
|
|
params: httpBody,
|
|
|
},
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// Dynamically generate headers for JavaScript
|
|
|
const headersCode = Object.entries(headers)
|
|
|
.map(([key, value]) => `"${key}": "${value}"`)
|
|
|
- .join(',\n');
|
|
|
+ .join(',\n')
|
|
|
|
|
|
// Format the body with indentation
|
|
|
- const jsonBody = JSON.stringify(object.body, null, 2); // 4-space indentation for JSON
|
|
|
+ const jsonBody = JSON.stringify(object.body, null, 2) // 4-space indentation for JSON
|
|
|
|
|
|
const code = `const url = "${url}";
|
|
|
|
|
|
@@ -33,13 +39,13 @@ fetch(url, {
|
|
|
.then(response => response.json())
|
|
|
.then(data => console.log(data))
|
|
|
.catch(error => console.error("Error:", error));
|
|
|
-`;
|
|
|
+`
|
|
|
|
|
|
return (
|
|
|
<Fence className="w-full" language="javascript">
|
|
|
{code}
|
|
|
</Fence>
|
|
|
- );
|
|
|
-};
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
-export default JavaScriptRequestRenderer;
|
|
|
+export default JavaScriptRequestRenderer
|