export type GetApiRecipesIdNutritionLabelArgs = {id: number, defaultCss?: boolean | undefined, showOptionalNutrients?: boolean | undefined, showZeroValues?: boolean | undefined, showIngredients?: boolean | undefined}; export type GetApiRecipesIdNutritionLabelOptions = {baseUrl?: string | undefined, apiKeyScheme?: string | undefined, fetch?: typeof fetch | undefined}; /** * Recipe Nutrition Label Widget * * GET /recipes/{id}/nutritionLabel */ export const getApiRecipesIdNutritionLabel = async (args: GetApiRecipesIdNutritionLabelArgs, options?: GetApiRecipesIdNutritionLabelOptions) => { const {baseUrl = "https://api.spoonacular.com", fetch: fetchFn = fetch, apiKeyScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") if (args.defaultCss != null) query.append("defaultCss", String(args.defaultCss)) if (args.showOptionalNutrients != null) query.append("showOptionalNutrients", String(args.showOptionalNutrients)) if (args.showZeroValues != null) query.append("showZeroValues", String(args.showZeroValues)) if (args.showIngredients != null) query.append("showIngredients", String(args.showIngredients)) if (apiKeyScheme !== undefined) headers.set("x-api-key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/recipes/${encodeURIComponent(String(args.id))}/nutritionLabel${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.text() };