From 81cf9620ffc5cd274d2554b043d773fa9f4a0209 Mon Sep 17 00:00:00 2001 From: a-honey Date: Sat, 4 Jan 2025 21:16:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EB=AA=A8=EB=8B=88=ED=84=B0?= =?UTF-8?q?=EB=A7=81=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=82=B4=20API=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/monitoring/ApiTestForm.tsx | 80 ++++++++++++++++++++++++++++ src/pages/monitoring/index.tsx | 3 ++ 2 files changed, 83 insertions(+) create mode 100644 src/pages/monitoring/ApiTestForm.tsx diff --git a/src/pages/monitoring/ApiTestForm.tsx b/src/pages/monitoring/ApiTestForm.tsx new file mode 100644 index 0000000..67d8e32 --- /dev/null +++ b/src/pages/monitoring/ApiTestForm.tsx @@ -0,0 +1,80 @@ +import { Button } from "../../components/ui/button"; +import { Textarea } from "../../components/ui/textarea"; +import fetchData from "../../api/fetchData"; +import { useState } from "react"; + +type MethodType = "GET" | "POST" | "PUT" | "DELETE"; + +export default function ApiTestForm() { + const [url, setUrl] = useState(""); + const [method, setMethod] = useState("GET"); + const [body, setBody] = useState("{}"); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + + try { + const parsedBody = body ? JSON.parse(body) : undefined; + + console.log( + "%cAPI 요청 정보:\n", + "background: #006980; color: white; padding: 4px; border-radius: 4px;", + { url, method, parsedBody } + ); + const res = await fetchData({ + url, + method, + body: parsedBody, + }); + + console.log( + "%cAPI 요청 결과:\n", + "background: green; color: white; padding: 4px; border-radius: 4px;", + res + ); + } catch (err) { + console.log("에러 발생:", err); + } + }; + + return ( +
+
+ + setUrl(e.target.value)} + className="w-full p-2 border rounded" + placeholder="/api 이하의 엔드포인트를 전부 입력해주세요(예: /admin-support/releases?page=0&perPage=10)" + required + /> +
+
+ + +
+
+ +