export type GetApiMethodKeyValueOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Flexible search by regex or glob * * GET /{method}/{key}/{value} */ export const getApiMethodKeyValue = async (options?: GetApiMethodKeyValueOptions) => { const {baseUrl = "https://api.dnsdb.info/dnsdb/v2", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/x-ndjson") if (apikey !== undefined) headers.set("X-API-KEY", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.method))}/${encodeURIComponent(String(args.key))}/${encodeURIComponent(String(args.value))}${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() };