'use client'; import { useId, useState } from 'react'; import { buildCurl, buildFetchSnippet, type ApiRequestInput, type HttpMethod } from '@/lib/xray/api-client'; import { ToolFrame } from './tool-frame'; import { TextField, SelectField } from './shared/fields'; import { OutputBlock } from './shared/output-block'; const METHODS: readonly HttpMethod[] = ['GET', 'POST', 'PUT', 'DELETE']; export function ApiRequestBuilder() { const [baseUrl, setBaseUrl] = useState('https://panel.example.com:2053'); const [token, setToken] = useState(''); const [path, setPath] = useState('/panel/api/inbounds/list'); const [method, setMethod] = useState('GET'); const [body, setBody] = useState(''); const bodyId = useId(); const showBody = method === 'POST' || method === 'PUT'; const input: ApiRequestInput = { baseUrl, token: token || '', path, method, body }; function reset() { setBaseUrl('https://panel.example.com:2053'); setToken(''); setPath('/panel/api/inbounds/list'); setMethod('GET'); setBody(''); } return (
setMethod(v as HttpMethod)} options={METHODS} />
{showBody ? (