### searchRecipes() PHP example Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/php/docs/Api/RecipesApi.md Example PHP client setup and call to searchRecipes(). Requires the autoloader and an API key configured via 'x-api-key'. The example sets many optional parameters with sample values and comments describing each parameter. ```php setApiKey('x-api-key', 'YOUR_API_KEY'); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer'); $apiInstance = new OpenAPI\Client\Api\RecipesApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $query = burger; // string | The (natural language) search query. $cuisine = italian; // string | The cuisine(s) of the recipes. One or more, comma separated (will be interpreted as 'OR'). See a full list of supported cuisines. $exclude_cuisine = greek; // string | The cuisine(s) the recipes must not match. One or more, comma separated (will be interpreted as 'AND'). See a full list of supported cuisines. $diet = vegetarian; // string | The diet for which the recipes must be suitable. See a full list of supported diets. $intolerances = gluten; // string | A comma-separated list of intolerances. All recipes returned must not contain ingredients that are not suitable for people with the intolerances entered. See a full list of supported intolerances. $equipment = pan; // string | The equipment required. Multiple values will be interpreted as 'or'. For example, value could be "blender, frying pan, bowl". $include_ingredients = tomato,cheese; // string | A comma-separated list of ingredients that should/must be used in the recipes. $exclude_ingredients = eggs; // string | A comma-separated list of ingredients or ingredient types that the recipes must not contain. $type = main course; // string | The type of recipe. See a full list of supported meal types. $instructions_required = true; // bool | Whether the recipes must have instructions. $fill_ingredients = false; // bool | Add information about the ingredients and whether they are used or missing in relation to the query. $add_recipe_information = false; // bool | If set to true, you get more information about the recipes returned. $add_recipe_nutrition = false; // bool | If set to true, you get nutritional information about each recipes returned. $author = coffeebean; // string | The username of the recipe author. $tags = 'tags_example'; // string | The tags (can be diets, meal types, cuisines, or intolerances) that the recipe must have. $recipe_box_id = 2468; // int | The id of the recipe box to which the search should be limited to. $title_match = Crock Pot; // string | Enter text that must be found in the title of the recipes. $max_ready_time = 20; // float | The maximum time in minutes it should take to prepare and cook the recipe. $min_servings = 1; // float | The minimum amount of servings the recipe is for. $max_servings = 8; // float | The maximum amount of servings the recipe is for. $ignore_pantry = false; // bool | Whether to ignore typical pantry items, such as water, salt, flour, etc. ``` -------------------------------- ### PHP example: Configure API key and call analyzeRecipe Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/php/README.md Sets up the API client with an API key (x-api-key) and calls the analyzeRecipe endpoint with a sample request body. The example includes optional prefix setup and custom HTTP client. It prints the result or catches exceptions. ```php setApiKey('x-api-key', 'YOUR_API_KEY'); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer'); $apiInstance = new OpenAPI\Client\Api\DefaultApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $analyze_recipe_request = {"title":"Spaghetti Carbonara","servings":2,"ingredients":["1 lb spaghetti","3.5 oz pancetta","2 Tbsps olive oil","1 egg","0.5 cup parmesan cheese"],"instructions":"Bring a large pot of water to a boil and season generously with salt. Add the pasta to the water once boiling and cook until al dente. Reserve 2 cups of cooking water and drain the pasta. "}; // \OpenAPI\Client\Model\AnalyzeRecipeRequest | Example request body. $language = en; // string | The input language, either \"en\" or \"de\". $include_nutrition = false; // bool | Whether nutrition data should be added to correctly parsed ingredients. $include_taste = false; // bool | Whether taste data should be added to correctly parsed ingredients. try { $result = $apiInstance->analyzeRecipe($analyze_recipe_request, $language, $include_nutrition, $include_taste); print_r($result); } catch (Exception $e) { echo 'Exception when calling DefaultApi->analyzeRecipe: ', $e->getMessage(), PHP_EOL; } ``` -------------------------------- ### PHP client setup and nutrient parameters for searchRecipesByNutrients Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/php/docs/Api/RecipesApi.md Example PHP client setup for the searchRecipesByNutrients call. It requires the autoloader, configures the 'x-api-key' API key (optionally with a Bearer prefix), and instantiates RecipesApi with a GuzzleHttp client. The snippet then declares example nutrient range variables used as parameters. ```php setApiKey('x-api-key', 'YOUR_API_KEY'); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // $config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('x-api-key', 'Bearer'); $apiInstance = new OpenAPI\Client\Api\RecipesApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $min_carbs = 10; // float | The minimum amount of carbohydrates in grams the recipe must have. $max_carbs = 100; // float | The maximum amount of carbohydrates in grams the recipe can have. $min_protein = 10; // float | The minimum amount of protein in grams the recipe must have. $max_protein = 100; // float | The maximum amount of protein in grams the recipe can have. $min_calories = 50; // float | The minimum amount of calories the recipe must have. $max_calories = 800; // float | The maximum amount of calories the recipe can have. $min_fat = 1; // float | The minimum amount of fat in grams the recipe must have. $max_fat = 100; // float | The maximum amount of fat in grams the recipe can have. $min_alcohol = 0; // float | The minimum amount of alcohol in grams the recipe must have. $max_alcohol = 100; // float | The maximum amount of alcohol in grams the recipe can have. $min_caffeine = 0; // float | The minimum amount of caffeine in milligrams the recipe must have. $max_caffeine = 100; // float | The maximum amount of caffeine in milligrams the recipe can have. $min_copper = 0; // float | The minimum amount of copper in milligrams the recipe must have. $max_copper = 100; // float | The maximum amount of copper in milligrams the recipe can have. $min_calcium = 0; // float | The minimum amount of calcium in milligrams the recipe must have. $max_calcium = 100; // float | The maximum amount of calcium in milligrams the recipe can have. $min_choline = 0; // float | The minimum amount of choline in milligrams the recipe must have. $max_choline = 100; // float | The maximum amount of choline in milligrams the recipe can have. $min_cholesterol = 0; // float | The minimum amount of cholesterol in milligrams the recipe must have. $max_cholesterol = 100; // float | The maximum amount of cholesterol in milligrams the recipe can have. $min_fluoride = 0; // float | The minimum amount of fluoride in milligrams the recipe must have. $max_fluoride = 100; // float | The maximum amount of fluoride in milligrams the recipe can have. $min_saturated_fat = 0; // float | The minimum amount of saturated fat in grams the recipe must have. $max_saturated_fat = 100; // float | The maximum amount of saturated fat in grams the recipe can have. $min_vitamin_a = 0; // float | The minimum amount of Vitamin A in IU the recipe must have. $max_vitamin_a = 100; // float | The maximum amount of Vitamin A in IU the recipe can have. $min_vitamin_c = 0; // float | The minimum amount of Vitamin C in milligrams the recipe must have. $max_vitamin_c = 100; // float | The maximum amount of Vitamin C in milligrams the recipe can have. $min_vitamin_d = 0; // float | The minimum amount of Vitamin D in micrograms the recipe must have. $max_vitamin_d = 100; // float | The maximum amount of Vitamin D in micrograms the recipe can have. ``` -------------------------------- ### Install via Setuptools Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/python/README.md Install the package using Setuptools for the current user. Use 'sudo python setup.py install' to install for all users. ```sh python setup.py install --user ``` -------------------------------- ### Getting Started example.h and example.cpp for spoonacular C++ Qt client Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/cpp/README.md These two files form the Getting Started example for the C++ Qt client. example.h declares the Example class with overloaded create() methods and a Q_SLOT exampleFunction1(). example.cpp implements them and shows how to configure the API key, connect to the analyzeRecipeSignal and error signal, and call analyzeRecipe() with a 5-second timeout. ```c++ #include #include "../client/OAIDefaultApi.h" using namespace test_namespace; class Example : public QObject { Q_OBJECT OAIAnalyzeRecipe_request create(); QString create(); bool create(); bool create(); public Q_SLOTS: void exampleFunction1(); }; ``` ```c++ #include "../client/OAIDefaultApi.h" #include "example.h" #include #include OAIAnalyzeRecipe_request Example::create(){ OAIAnalyzeRecipe_request obj; QString Example::create(){ QString obj; bool Example::create(){ bool obj; bool Example::create(){ bool obj; return obj; } void Example::exampleFunction1(){ OAIDefaultApi apiInstance; // Configure API key authorization: apiKeyScheme apiInstance.setApiKey("YOUR API KEY NAME","YOUR API KEY"); QEventLoop loop; connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignal, [&]() { loop.quit(); }); connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignalE, [&](QNetworkReply::NetworkError, QString error_str) { qDebug() << "Error happened while issuing request : " << error_str; loop.quit(); }); OAIAnalyzeRecipe_request oai_analyze_recipe_request = create(); // OAIAnalyzeRecipe_request | Example request body. QEventLoop loop; connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignal, [&]() { loop.quit(); }); connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignalE, [&](QNetworkReply::NetworkError, QString error_str) { qDebug() << "Error happened while issuing request : " << error_str; loop.quit(); }); QString language = create(); // QString | The input language, either \"en\" or \"de\". QEventLoop loop; connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignal, [&]() { loop.quit(); }); connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignalE, [&](QNetworkReply::NetworkError, QString error_str) { qDebug() << "Error happened while issuing request : " << error_str; loop.quit(); }); bool include_nutrition = create(); // bool | Whether nutrition data should be added to correctly parsed ingredients. QEventLoop loop; connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignal, [&]() { loop.quit(); }); connect(&apiInstance, &OAIDefaultApi::analyzeRecipeSignalE, [&](QNetworkReply::NetworkError, QString error_str) { qDebug() << "Error happened while issuing request : " << error_str; loop.quit(); }); bool include_taste = create(); // bool | Whether taste data should be added to correctly parsed ingredients. apiInstance.analyzeRecipe(oai_analyze_recipe_requestlanguageinclude_nutritioninclude_taste); QTimer::singleShot(5000, &loop, &QEventLoop::quit); loop.exec(); } ``` -------------------------------- ### Get Random Recipes with get_random_recipes_with_http_info Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/ruby/docs/RecipesApi.md Uses the get_random_recipes_with_http_info variant to obtain the response data, status code, and headers as an Array. The example assumes the same setup and opts as the basic get_random_recipes example. ```ruby begin # Get Random Recipes data, status_code, headers = api_instance.get_random_recipes_with_http_info(opts) p status_code # => 2xx p headers # => { ... } p data # => rescue OpenapiClient::ApiError => e puts "Error when calling RecipesApi->get_random_recipes_with_http_info: #{e}" end ``` -------------------------------- ### GET /recipes/complexSearch Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/javascript/docs/RecipesApi.md This snippet documents the searchRecipes operation from the RecipesApi, which corresponds to the GET /recipes/complexSearch endpoint. It includes all query parameters and a basic request/response example. ```APIDOC ## [GET] /recipes/complexSearch ### Description Searches for recipes based on a natural language query and various optional filters such as cuisine, diet, intolerances, and nutritional constraints. ### Method GET ### Endpoint /recipes/complexSearch ### Parameters #### Query Parameters - **query** (String) - Required - The (natural language) search query. - **cuisine** (String) - Optional - The cuisine(s) of the recipes. One or more, comma separated (will be interpreted as 'OR'). See a full list of supported cuisines. - **excludeCuisine** (String) - Optional - The cuisine(s) the recipes must not match. One or more, comma separated (will be interpreted as 'AND'). See a full list of supported cuisines. - **diet** (String) - Optional - The diet for which the recipes must be suitable. See a full list of supported diets. - **intolerances** (String) - Optional - A comma-separated list of intolerances. All recipes returned must not contain ingredients that are not suitable for people with the intolerances entered. See a full list of supported intolerances. - **equipment** (String) - Optional - The equipment required. Multiple values will be interpreted as 'or'. For example, value could be "blender, frying pan, bowl". - **includeIngredients** (String) - Optional - A comma-separated list of ingredients that should/must be used in the recipes. - **excludeIngredients** (String) - Optional - A comma-separated list of ingredients or ingredient types that the recipes must not contain. - **type** (String) - Optional - The type of recipe. See a full list of supported meal types. - **instructionsRequired** (Boolean) - Optional - Whether the recipes must have instructions. - **fillIngredients** (Boolean) - Optional - Add information about the ingredients and whether they are used or missing in relation to the query. - **addRecipeInformation** (Boolean) - Optional - If set to true, you get more information about the recipes returned. - **addRecipeNutrition** (Boolean) - Optional - If set to true, you get nutritional information about each recipes returned. - **author** (String) - Optional - The username of the recipe author. - **tags** (String) - Optional - The tags (can be diets, meal types, cuisines, or intolerances) that the recipe must have. - **recipeBoxId** (Number) - Optional - The id of the recipe box to which the search should be limited to. - **titleMatch** (String) - Optional - Enter text that must be found in the title of the recipes. - **maxReadyTime** (Number) - Optional - The maximum time in minutes it should take to prepare and cook the recipe. - **minServings** (Number) - Optional - The minimum amount of servings the recipe is for. - **maxServings** (Number) - Optional - The maximum amount of servings the recipe is for. - **ignorePantry** (Boolean) - Optional - Whether to ignore typical pantry items, such as water, salt, flour, etc. Defaults to false. - **sort** (String) - Optional - The strategy to sort recipes by. See a full list of supported sorting options. - **sortDirection** (String) - Optional - The direction in which to sort. Must be either 'asc' (ascending) or 'desc' (descending). - **minCarbs** (Number) - Optional - The minimum amount of carbohydrates in grams the recipe must have. - **maxCarbs** (Number) - Optional - The maximum amount of carbohydrates in grams the recipe can have. - **minProtein** (Number) - Optional - The minimum amount of protein in grams the recipe must have. - **maxProtein** (Number) - Optional - The maximum amount of protein in grams the recipe can have. - **minCalories** (Number) - Optional - The minimum amount of calories the recipe must have. - **maxCalories** (Number) - Optional - The maximum amount of calories the recipe can have. - **minFat** (Number) - Optional - The minimum amount of fat in grams the recipe must have. - **maxFat** (Number) - Optional - The maximum amount of fat in grams the recipe can have. - **minAlcohol** (Number) - Optional - The minimum amount of alcohol in grams the recipe must have. - **maxAlcohol** (Number) - Optional - The maximum amount of alcohol in grams the recipe can have. - **minCaffeine** (Number) - Optional - The minimum amount of caffeine in milligrams the recipe must have. - **maxCaffeine** (Number) - Optional - The maximum amount of caffeine in milligrams the recipe can have. - **minCopper** (Number) - Optional - The minimum amount of copper in milligrams the recipe must have. - **maxCopper** (Number) - Optional - The maximum amount of copper in milligrams the recipe can have. - **minCalcium** (Number) - Optional - The minimum amount of calcium in milligrams the recipe must have. - **maxCalcium** (Number) - Optional - The maximum amount of calcium in milligrams the recipe can have. - **minCholine** (Number) - Optional - The minimum amount of choline in milligrams the recipe must have. - **maxCholine** (Number) - Optional - The maximum amount of choline in milligrams the recipe can have. - **minCholesterol** (Number) - Optional - The minimum amount of cholesterol in milligrams the recipe must have. - **maxCholesterol** (Number) - Optional - The maximum amount of cholesterol in milligrams the recipe can have. - **minFluoride** (Number) - Optional - The minimum amount of fluoride in milligrams the recipe must have. - **maxFluoride** (Number) - Optional - The maximum amount of fluoride in milligrams the recipe can have. - **minFolate** (Number) - Optional - The minimum amount of folate in micrograms the recipe must have. - **maxFolate** (Number) - Optional - The maximum amount of folate in micrograms the recipe can have. - **minFolicAcid** (Number) - Optional - The minimum amount of folic acid in micrograms the recipe must have. - **maxFolicAcid** (Number) - Optional - The maximum amount of folic acid in micrograms the recipe can have. - **minIodine** (Number) - Optional - The minimum amount of iodine in micrograms the recipe must have. - **maxIodine** (Number) - Optional - The maximum amount of iodine in micrograms the recipe can have. - **minIron** (Number) - Optional - The minimum amount of iron in milligrams the recipe must have. - **maxIron** (Number) - Optional - The maximum amount of iron in milligrams the recipe can have. - **minMagnesium** (Number) - Optional - The minimum amount of magnesium in milligrams the recipe must have. - **maxMagnesium** (Number) - Optional - The maximum amount of magnesium in milligrams the recipe can have. - **minManganese** (Number) - Optional - The minimum amount of manganese in milligrams the recipe must have. - **maxManganese** (Number) - Optional - The maximum amount of manganese in milligrams the recipe can have. - **minPhosphorus** (Number) - Optional - The minimum amount of phosphorus in milligrams the recipe must have. - **maxPhosphorus** (Number) - Optional - The maximum amount of phosphorus in milligrams the recipe can have. - **minPotassium** (Number) - Optional - The minimum amount of potassium in milligrams the recipe must have. - **maxPotassium** (Number) - Optional - The maximum amount of potassium in milligrams the recipe can have. - **minSelenium** (Number) - Optional - The minimum amount of selenium in micrograms the recipe must have. - **maxSelenium** (Number) - Optional - The maximum amount of selenium in micrograms the recipe can have. - **minSodium** (Number) - Optional - The minimum amount of sodium in milligrams the recipe must have. - **maxSodium** (Number) - Optional - The maximum amount of sodium in milligrams the recipe can have. - **minSugar** (Number) - Optional - The minimum amount of sugar in grams the recipe must have. - **maxSugar** (Number) - Optional - The maximum amount of sugar in grams the recipe can have. - **minZinc** (Number) - Optional - The minimum amount of zinc in milligrams the recipe must have. - **maxZinc** (Number) - Optional - The maximum amount of zinc in milligrams the recipe can have. - **offset** (Number) - Optional - The number of results to skip (between 0 and 900). - **number** (Number) - Optional - The maximum number of items to return (between 1 and 100). Defaults to 10. ### Request Example ``` GET /recipes/complexSearch?query=pasta&cuisine=italian&number=10 ``` ### Response #### Success Response (200) - **data** (Object) - The search results containing recipes and metadata. #### Response Example ```json { "results": [], "offset": 0, "number": 10, "totalResults": 0 } ``` ``` -------------------------------- ### Python example: create and convert RecipeInformationWinePairing Source: https://github.com/ddsky/spoonacular-api-clients/blob/master/python/docs/RecipeInformationWinePairing.md Shows how to import the model, create an instance from a JSON string, print its JSON representation, convert to a dict, and create an instance from a dict. ```python from spoonacular.models.recipe_information_wine_pairing import RecipeInformationWinePairing # TODO update the JSON string below json = "{}" # create an instance of RecipeInformationWinePairing from a JSON string recipe_information_wine_pairing_instance = RecipeInformationWinePairing.from_json(json) # print the JSON string representation of the object print(RecipeInformationWinePairing.to_json()) # convert the object into a dict recipe_information_wine_pairing_dict = recipe_information_wine_pairing_instance.to_dict() # create an instance of RecipeInformationWinePairing from a dict recipe_information_wine_pairing_from_dict = RecipeInformationWinePairing.from_dict(recipe_information_wine_pairing_dict) ```