export type CreateApiRecipesVisualizeNutritionArgs = {'Content-Type'?: ('application/x-www-form-urlencoded' | 'application/json' | 'multipart/form-data') | undefined, Accept?: ('application/json' | 'text/html' | 'media/*') | undefined, language?: ('en' | 'de') | undefined, body: string}; export type CreateApiRecipesVisualizeNutritionOptions = {baseUrl?: string | undefined, apiKeyScheme?: string | undefined, fetch?: typeof fetch | undefined}; /** * Recipe Nutrition Widget * * POST /recipes/visualizeNutrition */ export const createApiRecipesVisualizeNutrition = async (args: CreateApiRecipesVisualizeNutritionArgs, options?: CreateApiRecipesVisualizeNutritionOptions) => { const {baseUrl = "https://api.spoonacular.com", fetch: fetchFn = fetch, apiKeyScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "text/html") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.language != null) query.append("language", String(args.language)) if (apiKeyScheme !== undefined) headers.set("x-api-key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/recipes/visualizeNutrition${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };