export type GetApiApiAbnfExtractArgs = {url?: string | undefined, doc?: string | undefined}; export type GetApiApiAbnfExtractOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Extract ABNF using BAP aex * * GET /api/abnf/extract */ export const getApiApiAbnfExtract = async (args: GetApiApiAbnfExtractArgs, options?: GetApiApiAbnfExtractOptions) => { const {baseUrl = "https://author-tools.ietf.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.url != null) query.append("url", String(args.url)) if (args.doc != null) query.append("doc", String(args.doc)) const url = `${baseUrl.replace(/\/+$/, '')}/api/abnf/extract${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };