export type GetApiGetXMLArgs = {query: string}; export type GetApiGetXMLOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /GetXML */ export const getApiGetXML = async (args: GetApiGetXMLArgs, options?: GetApiGetXMLOptions) => { const {baseUrl = "https://cadsrapi.cancer.gov/caDSR5.0/rest/getXML", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/xml") if (args.query != null) query.append("query", String(args.query)) const url = `${baseUrl.replace(/\/+$/, '')}/GetXML${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.blob() };