export type GetApiTriviaArgs = {id?: unknown | undefined}; export type GetApiTriviaOptions = {baseUrl?: string | undefined, XFungeneratorsApiSecret?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get a Trivia entry for a given id. Retrieves a trivia question and answer based on the id. * * GET /trivia */ export const getApiTrivia = async (args: GetApiTriviaArgs, options?: GetApiTriviaOptions) => { const {baseUrl = "https://api.fungenerators.com", fetch: fetchFn = fetch, XFungeneratorsApiSecret} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (XFungeneratorsApiSecret !== undefined) headers.set("X-Fungenerators-Api-Secret", XFungeneratorsApiSecret) const url = `${baseUrl.replace(/\/+$/, '')}/trivia${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 };