static / assets /ApiTester-BE2AsWga.js
admin08077's picture
Upload 131 files
777dff7 verified
import{r as s,j as e}from"./react-_fH1j4AW.js";import{S as N}from"./index-Nqm_ElTk.js";import{L as f}from"./LoadingSpinner-C3NwW9hm.js";import{JsonTreeNavigator as v}from"./JsonTreeNavigator-CGuqWmNG.js";import"./@braintree-9Zuj5s7N.js";import"./react-dom-B47xkeQg.js";import"./scheduler-DYLXRpC5.js";import"./mermaid-CwNlsT42.js";import"./dayjs-LlU9W_sF.js";import"./d3-transition-593SbTzI.js";import"./d3-timer-DdKHrDhs.js";import"./d3-dispatch-kxCwF96_.js";import"./d3-interpolate-CfLzPKWk.js";import"./d3-color-amxIadob.js";import"./d3-selection-C52G7wmG.js";import"./d3-ease-DRPgKoYJ.js";import"./d3-zoom-Dc8HCWOS.js";import"./dompurify-J5RlrwSC.js";import"./dagre-d3-es-CXvdFQqV.js";import"./lodash-es-CKQobiyk.js";import"./d3-shape-C6amFesj.js";import"./d3-path-CimkQT29.js";import"./d3-fetch-BOsq7VnW.js";import"./khroma-DUX6PT6k.js";import"./uuid-DhYbOkY1.js";import"./d3-scale-BchcX-lF.js";import"./internmap-BkD7Hj8s.js";import"./d3-array-DGRYoJHh.js";import"./d3-format-CzD4bSOQ.js";import"./d3-time-format-CUNN4Ell.js";import"./d3-time-6cSPyVSY.js";import"./d3-axis-DSWTncID.js";import"./elkjs-BS_sNva5.js";import"./cytoscape-Copgxxlq.js";import"./cytoscape-cose-bilkent-DNVwk4oY.js";import"./cose-base-HlRMd3jM.js";import"./layout-base-BVPXtQQC.js";import"./d3-sankey-DgqkLiUE.js";import"./d3-scale-chromatic-B-NsZVaP.js";import"./ts-dedent-DrFu-skq.js";import"./stylis-D5iaQeiq.js";import"./mdast-util-from-markdown-CLAsVoWb.js";import"./micromark-CTBPIv-_.js";import"./micromark-util-combine-extensions-Bka6Sc1c.js";import"./micromark-util-chunked-DrRIdSP-.js";import"./micromark-factory-space-x2vfxbz5.js";import"./micromark-util-character-Bcm1tP9o.js";import"./micromark-core-commonmark-AH8VCgT7.js";import"./micromark-util-classify-character-Cq7Fg3xE.js";import"./micromark-util-resolve-all-PQCKh0dx.js";import"./decode-named-character-reference-C3-224fz.js";import"./micromark-util-subtokenize-QwsxNXk2.js";import"./micromark-factory-destination-CypD_wgM.js";import"./micromark-factory-label-CRHH4ZHP.js";import"./micromark-factory-title-B7kCBvC9.js";import"./micromark-factory-whitespace-B322EA6O.js";import"./micromark-util-normalize-identifier-C9ANKk3v.js";import"./micromark-util-html-tag-name-DbKNfynz.js";import"./micromark-util-decode-numeric-character-reference-DRnCnno4.js";import"./micromark-util-decode-string-DJl8Y_PO.js";import"./unist-util-stringify-position-Ch_qCilz.js";import"./mdast-util-to-string-C_aolqmU.js";const Ae=()=>{const[o,g]=s.useState("GET"),[n,b]=s.useState("https://jsonplaceholder.typicode.com/todos/1"),[l,j]=s.useState(`{
"title": "foo",
"body": "bar",
"userId": 1
}`),[m,u]=s.useState(null),[a,h]=s.useState(null),[i,p]=s.useState(!1),[d,c]=s.useState(""),y=s.useCallback(async()=>{p(!0),c(""),u(null),h(null);const t={method:o,headers:{"Content-Type":"application/json"}};if(o!=="GET")try{t.body=JSON.stringify(JSON.parse(l))}catch{c("Invalid JSON in request body."),p(!1);return}try{const r=await fetch(n,t),x=await r.json();u(x),h(r.status)}catch(r){const x=r instanceof Error?r.message:"An unknown error occurred.";c(`Request failed: ${x}. Note: Browser security may block requests to certain domains (CORS).`)}finally{p(!1)}},[n,o,l]);return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold text-slate-100 flex items-center",children:[e.jsx(N,{}),e.jsx("span",{className:"ml-3",children:"API Tester"})]}),e.jsx("p",{className:"text-slate-400 mt-1",children:"Send HTTP requests and view responses. Uses a public test API."})]}),e.jsxs("div",{className:"flex flex-col flex-grow min-h-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsxs("select",{value:o,onChange:t=>g(t.target.value),className:"px-4 py-2 rounded-md bg-slate-800 border border-slate-700 font-bold",children:[e.jsx("option",{children:"GET"}),e.jsx("option",{children:"POST"}),e.jsx("option",{children:"PUT"}),e.jsx("option",{children:"DELETE"}),e.jsx("option",{children:"PATCH"})]}),e.jsx("input",{type:"text",value:n,onChange:t=>b(t.target.value),placeholder:"https://api.example.com/data",className:"flex-grow px-4 py-2 rounded-md bg-slate-900 border border-slate-700 font-mono text-sm focus:ring-2 focus:ring-cyan-500 focus:outline-none"}),e.jsx("button",{onClick:y,disabled:i,className:"px-6 py-2 bg-cyan-500 text-slate-900 font-bold rounded-md hover:bg-cyan-400 disabled:bg-slate-600 flex items-center gap-2",children:i?e.jsx(f,{}):"Send"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 flex-grow min-h-0",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-sm font-medium text-slate-400 mb-2",children:"Request Body (JSON)"}),e.jsx("textarea",{value:l,onChange:t=>j(t.target.value),disabled:o==="GET",className:"flex-grow p-4 bg-slate-900 border border-slate-700 rounded-md resize-none font-mono text-sm text-cyan-300 focus:ring-2 focus:ring-cyan-500 focus:outline-none disabled:bg-slate-800/50"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("label",{className:"text-sm font-medium text-slate-400 mb-2",children:"Response"}),e.jsxs("div",{className:"flex-grow p-4 bg-slate-800/50 border border-slate-700/50 rounded-md overflow-y-auto relative",children:[a&&e.jsxs("div",{className:`absolute top-2 right-2 px-2 py-1 text-xs font-bold rounded ${a>=200&&a<300?"bg-green-500/20 text-green-300":"bg-red-500/20 text-red-300"}`,children:["Status: ",a]}),i&&e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(f,{})}),d&&e.jsx("p",{className:"text-red-400",children:d}),m&&!i&&e.jsx(v,{data:m}),!i&&!m&&!d&&e.jsx("div",{className:"text-slate-500 h-full flex items-center justify-center",children:"Response will appear here."})]})]})]}),e.jsxs("div",{className:"mt-4 p-3 bg-slate-800/50 border border-slate-700/50 rounded-lg text-xs text-slate-400",children:[e.jsx("h4",{className:"font-bold text-slate-300 mb-1",children:"About CORS"}),e.jsx("p",{children:"This API tester runs in your browser. For security reasons, browsers restrict web pages from making requests to a different domain than the one that served the page. This is known as the Cross-Origin Resource Sharing (CORS) policy. If a request fails with a CORS error, it means the target server (e.g., `https://api.example.com`) does not permit requests from this application. The `Access-Control-Allow-Origin` header must be configured on the server-side."})]})]})]})};export{Ae as ApiTester};
//# sourceMappingURL=ApiTester-BE2AsWga.js.map