export type GetApiShakespeareQuoteOptions = {baseUrl?: string | undefined, XFungeneratorsApiSecret?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get a random Shakespeare quote. * * GET /shakespeare/quote */ export const getApiShakespeareQuote = async (options?: GetApiShakespeareQuoteOptions) => { const {baseUrl = "http://api.fungenerators.com", fetch: fetchFn = fetch, XFungeneratorsApiSecret} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (XFungeneratorsApiSecret !== undefined) headers.set("X-Fungenerators-Api-Secret", XFungeneratorsApiSecret) const url = `${baseUrl.replace(/\/+$/, '')}/shakespeare/quote${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 (await res.json()) as unknown };