Spaces:
Running
Running
| import{r as t,j as e}from"./react-B-lWpQRQ.js";import{u as E,aG as A,L as g}from"./index-DyMS-nC-.js";import"./marked-CesSW9Du.js";import"./@braintree-DY5JYOZd.js";import"./react-dom-CU2yWD-Y.js";import"./scheduler-DYLXRpC5.js";import"./@google-xfXoiafW.js";import"./idb-Dob3nYDb.js";import"./axe-core-CA05Kxsw.js";import"./@mermaid-js-Ce0__7Tp.js";import"./langium-B_PGe6V2.js";import"./vscode-jsonrpc-2tvYB2ki.js";import"./chevrotain-D5DQZOif.js";import"./@chevrotain-DMYZVohV.js";import"./lodash-es-CKTcnrxn.js";import"./chevrotain-allstar-eFSt8-qu.js";import"./vscode-languageserver-types-NoPvPymt.js";import"./vscode-languageserver-textdocument-CKBVUiR3.js";import"./vscode-uri-CoxP0whD.js";const V=()=>{const[u,N]=t.useState("https://jsonplaceholder.typicode.com/posts/1"),[l,b]=t.useState("GET"),[i,v]=t.useState(`{ | |
| "Content-Type": "application/json" | |
| }`),[c,S]=t.useState(""),[y,d]=t.useState(null),[a,f]=t.useState(null),[m,x]=t.useState(null),[p,h]=t.useState(!1),{addNotification:j}=E(),w=async()=>{h(!0),d(null),f(null),x(null);const s=performance.now();try{const r=i?JSON.parse(i):{},n=await fetch(u,{method:l,headers:r,body:l!=="GET"&&c?c:void 0}),o=performance.now();x(o-s),f(n.status);const T=await n.json();d(JSON.stringify(T,null,2)),j("Request successful!","success")}catch(r){const n=performance.now();x(n-s);const o=r instanceof Error?r.message:"An unknown error occurred";d(o),j(o,"error")}finally{h(!1)}};return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center",children:[e.jsx(A,{}),e.jsx("span",{className:"ml-3",children:"API Endpoint Tester"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"A simple UI to make requests to API endpoints (like Postman lite)."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-6 min-h-0",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{value:l,onChange:s=>b(s.target.value),className:"p-2 bg-surface border rounded",children:[e.jsx("option",{children:"GET"}),e.jsx("option",{children:"POST"}),e.jsx("option",{children:"PUT"}),e.jsx("option",{children:"DELETE"})]}),e.jsx("input",{value:u,onChange:s=>N(s.target.value),placeholder:"https://api.example.com/data",className:"flex-grow p-2 bg-surface border rounded"})]}),e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsx("label",{className:"text-sm mb-1",children:"Headers (JSON)"}),e.jsx("textarea",{value:i,onChange:s=>v(s.target.value),className:"flex-grow p-2 bg-surface border rounded font-mono text-xs"})]}),e.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[e.jsx("label",{className:"text-sm mb-1",children:"Body (JSON)"}),e.jsx("textarea",{value:c,onChange:s=>S(s.target.value),className:"flex-grow p-2 bg-surface border rounded font-mono text-xs"})]}),e.jsx("button",{onClick:w,disabled:p,className:"btn-primary w-full py-3",children:p?e.jsx(g,{}):"Send Request"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Response"}),a&&e.jsxs("div",{className:"flex gap-4 text-sm",children:[e.jsxs("span",{className:a>=200&&a<300?"text-green-500":"text-red-500",children:["Status: ",a]}),e.jsxs("span",{children:["Time: ",m==null?void 0:m.toFixed(0),"ms"]})]})]}),e.jsx("div",{className:"flex-grow p-2 bg-background border rounded overflow-auto",children:p?e.jsx("div",{className:"flex justify-center items-center h-full",children:e.jsx(g,{})}):e.jsx("pre",{className:"font-mono text-xs",children:y})})]})]})]})};export{V as ApiEndpointTester}; | |
| //# sourceMappingURL=ApiEndpointTester-CdpMBY-S.js.map | |