export type GetApiRecipesIdIngredientWidgetPngArgs = {id: number, measure?: ('us' | 'metric') | undefined}; export type GetApiRecipesIdIngredientWidgetPngOptions = {baseUrl?: string | undefined, apiKeyScheme?: string | undefined, fetch?: typeof fetch | undefined}; /** * Ingredients by ID Image * * GET /recipes/{id}/ingredientWidget.png */ export const getApiRecipesIdIngredientWidgetPng = async (args: GetApiRecipesIdIngredientWidgetPngArgs, options?: GetApiRecipesIdIngredientWidgetPngOptions) => { const {baseUrl = "https://api.spoonacular.com", fetch: fetchFn = fetch, apiKeyScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/png") if (args.measure != null) query.append("measure", String(args.measure)) if (apiKeyScheme !== undefined) headers.set("x-api-key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/recipes/${encodeURIComponent(String(args.id))}/ingredientWidget.png${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() };