Food is a topic of universal interest irrespective of cultures, countries, and generations. The advent of the internet has only increased this interest, for users are constantly looking out for new recipes, ingredients, food photos, and other food-related information online. So much so, that businesses are also looking to leverage this user interest by using food-related information as a means to market products and attract customers. All this has led to the emergence of several REST APIs that deliver food-related content. One such API is the Tasty API. In this article, we will be learning about this API and its features.
What is the Tasty API
Tasty.co is a food recipe application. Though Tasty was originally started as a Facebook page, it quickly rose in popularity. Currently, it has a website, Android/iOS applications as well as pages on other social media platforms like Youtube and Instagram with millions of followers. At its core, Tasty is a food recipe application that provides textual and video-based recipes. In addition, it allows users to search for recipes by name, ingredients, or tags (which are labels that are attached to a recipe to categorize it). The Tasty API is an API for Tasty.co. It provides various endpoints that provide a list of recipes, details of an individual recipe, a list of available tags, and much more!
Who can use the Tasty API?
Restaurants/Food websites – Restaurant websites/mobile applications can utilize the Tasty API to display recipes/food videos as an additional feature to their users. Similarly, existing food websites and food bloggers can make use of the Tasty API to provide additional recipes, allow users to search for recipes by ingredient, name, etc.
Individual Businesses – Individual businesses that sell specific food products can make use of the Tasty API. Thus, by displaying recipes that use their food product as an ingredient, businesses can market their products.
How does the Tasty API work?
The Tasty API is a REST API. In simple terms, an application can use a REST API to query for data. A REST API exposes HTTP URLs which are also known as REST endpoints. An application that wishes to obtain information from the REST API (also known as a client application), needs to query the particular REST endpoint. While querying, it needs to supply the endpoint URL, request parameters (any information required by the endpoint), and authentication information (an API key). The REST endpoint then processes the request. It returns an HTTP status code indicating whether the request was successful or not. It may also optionally return data corresponding to the request.
The Tasty API works on the same principles. It exposes several endpoints that return information like a list of recipes, a list of tags, details about an individual recipe, etc. An application can query an endpoint by supplying its URL, the API key, and request parameters (like keyword by which to search a recipe, number of recipes to return, etc.). The Tasty API then queries the Tasty.co service and returns the requested information.
How to use the Tasty API?
You can use RapidAPI to connect to the Tasty API. Not only does RapidAPI list all of the API endpoints, but it also allows executing an API endpoint from the browser itself. Thus, developers can test the endpoint to understand the type of data that it returns without having to write any code. Moreover, RapidAPI also provides code snippets to query the API endpoints in popular programming languages. Thus, an application developer can use these code snippets without writing code from scratch.
To use RapidAPI to connect to the Tasty API, you need to follow the steps given below.
Step 1 – Signing Up
The first step is to create a RapidAPI account as described below.
a. Enter the Tasty RapidAPI URL (https://rapidapi.com/apidojo/api/tasty ) in a browser. Click on the Log In/Sign Up button in the top right corner. This redirects to the following authentication page:
b. Authenticate yourself using any of the methods shown on the page. I will choose to log in with Google. Upon successful authentication, the following page is displayed:
Step 2 – Subscribing to the Tasty API
In order to execute an API endpoint, you need to subscribe to the Tasty API. The Tasty API is a freemium API, which means there are free as well as paid plans. The free plan allows 500 requests per month.
To subscribe to the Tasty API, you need to do the following:
a. Click on the Pricing Tab. This displays the following screen:
b. Select the plan that is appropriate for you. I have selected the Basic (Free) plan. This displays the following screen:
Step 3 – Executing an endpoint
As explained earlier, RapidAPI allows executing an endpoint and viewing the response within the browser itself.
To execute an endpoint, you need to do the following:
a. Click on the EndPoints tab. All the available endpoints are displayed on the left:
b. Click the endpoint that you would like to execute. I have selected the recipes/auto-complete endpoint. Click the Test Endpoint button:
c. View the Response in the Results tab:
Step 4 – Obtaining a code snippet
As explained earlier, the Tasty API is a REST API and can be invoked by application code in any programming language. Since a REST API exposes its endpoints as HTTP URLs, a programming language-specific HTTP client library needs to be used to invoke an API endpoint. Most programming languages support multiple HTTP libraries. Not only does RapidAPI provides code snippets in various programming languages, but it provides code for multiple HTTP libraries in each programming language. Thus, this code can be copied and used as required.
For example, to obtain a code snippet in Javascript using the jQuery HTTP library, you need to do the following:
a. Click on Javascript -> jQuery in the Code Snippets tab:
b. Copy the Javascript code shown and use it as desired:
Tasty API Endpoints
Let us now take a detailed look at the Tasty API endpoints.
recipes/auto-complete
The recipes/auto-complete endpoint returns a list of recipes that match the selected search term. It accepts a String parameter called prefix. This is a mandatory parameter that specifies the string to be searched. The JSON object returned contains an array that specifies the names of items that match the search term.
recipes/list
The recipes/list endpoint returns a list of recipes. It accepts parameters corresponding to from (a numeric value that specifies the offset from where to start the returned result) and size (a numeric value that specifies the number of results to return). Both these are mandatory parameters. The from parameter has a default value of 0 and the size parameter has a default value of 20. It also accepts an optional String parameter called tags (a value returned by the /tags/list endpoint that specifies the tag to search) and another optional String parameter called q (which specifies the name of food or ingredient to search by). It returns a JSON array corresponding to a list of recipes. For each recipe, it returns information like the recipe name, description, preparation time, link to the video recipe, etc.
recipes/detail
The recipes/detail endpoint returns information about an individual recipe like ingredients, nutrition info, preparation method, etc. It accepts a numeric parameter called id. This is a mandatory parameter that specifies the id of a recipe. It can be obtained from the recipes/list endpoint. The JSON object returned includes the details of the recipe.
tags/list
The tags/list endpoint returns a list of the available tags. This can be used to filter the results returned by the recipes/list endpoint. It does not accept any parameters. It returns a JSON array corresponding to the tags list. For each tag, it returns information like the tag name, cuisine, etc.
feeds/list
The feeds/list endpoint returns a feed about the latest trending recipes. It accepts parameters corresponding to from (a numeric value that specifies the offset from where to start the returned result), size (a numeric value that specifies the number of results to return), vegetarian (a boolean flag that specifies that only vegetarian recipes should be returned) and timezone (specifies the timezone of the user’s location). All these are mandatory parameters. It returns a JSON array. Each element in the array contains details about the recipe like its name, preparation time, thumbnail URL, video URL, etc.
recipes/list-similarities
The recipes/list-similarities endpoint returns a list of recipes that are similar to the specified recipe. It accepts a numeric parameter called id. This is a mandatory parameter that specifies the id of a recipe. It can be obtained from the recipes/list endpoint. The JSON object returned contains an array. Each element in the array includes information about a recipe like its name, description, video URL, etc. Note that this API endpoint is deprecated which means that it may no longer be accurate/useful and is not recommended for use.
How to use the Tasty API with various programming languages
As explained earlier, RapidAPI provides code snippets in various programming languages like Java, Python, PHP, Ruby, Javascript, NodeJS to name a few. Moreover, it provides code for multiple HTTP libraries in each programming language. Let us take a look at a few code samples.
Using the Tasty API with Java
There are several HTTP client libraries available for Java, like OkHttp, Unirest, AsyncHttp, and java.net.http. The following code demonstrates how you can invoke the recipes/auto-complete API endpoint using the OkHttp library:
OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://tasty.p.rapidapi.com/recipes/auto-complete?prefix=chicken%20soup") .get() .addHeader("x-rapidapi-key", "<your key here>") .addHeader("x-rapidapi-host", "tasty.p.rapidapi.com") .build(); Response response = client.newCall(request).execute();
Using the Tasty API with Python
Like Java, there are several HTTP client libraries available for Python like http.client, Requests, and Unirest. The following code demonstrates how you can invoke the recipes/auto-complete API endpoint using the Requests library:
import requests url = "https://tasty.p.rapidapi.com/recipes/auto-complete" querystring = {"prefix":"chicken soup"} headers = { 'x-rapidapi-key': "<your key here>", 'x-rapidapi-host': "tasty.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
Using the Tasty API with PHP
PHP also has many HTTP client libraries like cURL, HTTP v1, HTTP v2, and Unirest. The code below demonstrates how you can invoke the recipes/auto-complete API endpoint using the HTTP v1 library:
<?php $request = new HttpRequest(); $request->setUrl('https://tasty.p.rapidapi.com/recipes/auto-complete'); $request->setMethod(HTTP_METH_GET); $request->setQueryData([ 'prefix' => 'chicken soup' ]); $request->setHeaders([ 'x-rapidapi-key' => '<your key here>', 'x-rapidapi-host' => 'tasty.p.rapidapi.com' ]); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }
Using the Tasty API with Ruby
Ruby has two main HTTP client libraries. These are net::http and Unirest. The code below demonstrates how you can invoke the recipes/auto-complete API endpoint using the net::http client:
require 'uri' require 'net/http' require 'openssl' url = URI("https://tasty.p.rapidapi.com/recipes/auto-complete?prefix=chicken%20soup") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = '<your key here>' request["x-rapidapi-host"] = 'tasty.p.rapidapi.com' response = http.request(request) puts response.read_body
Using the Tasty API with Javascript
Like other programming languages, Javascript too has many HTTP client libraries like jQuery, fetch, XMLHttpRequest, and Axios. The code below demonstrates how you can invoke the recipes/auto-complete API endpoint using the Axios library:
import axios from "axios"; const options = { method: 'GET', url: 'https://tasty.p.rapidapi.com/recipes/auto-complete', params: {prefix: 'chicken soup'}, headers: { 'x-rapidapi-key': '<your key here>', 'x-rapidapi-host': 'tasty.p.rapidapi.com' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); });
In addition, RapidAPI can also be used to obtain code snippets in many other programming languages like Node.js, C, Kotlin, Swift, etc.
What are the benefits of the Tasty API?
Simplicity – The most important benefit of the Tasty API is that it is very simple and easy to use. All the API endpoints and their parameters are self-explanatory. This enables developers to understand and use the API without a steep learning curve.
Comprehensive Data – Another important benefit of the Tasty API is that its data is comprehensive. It has data about millions of recipes across different cuisines, food types, and categories. This makes the API an excellent choice for anyone looking for extensive recipe information.
Minimalistic – Finally, the Tasty API is minimalistic. It provides only a handful of endpoints that provide the basic features required by its target users. Thus, developers are saved the time and effort of having to browse through tons of API methods.
Other Food APIs
There are several other Food APIs available on RapidAPI. Some of these are as follows:
- The Yummly API – The Yummly API is an API for yummly.com which is a food website. It exposes endpoints that provide a list of recipes, food reviews, etc.
- Recipe, Food, Nutrition API – The Recipe, Food, Nutrition API is an API for spoonacular.com which is a food, nutrition, and recipe website. It exposes various endpoints that provide recipe, ingredient, and product information.
- The Cocktail DB API – The Cocktail DB API is an API that provides data on alcohol and cocktails. It exposes various endpoints that allow searching for a cocktail by name, listing a list of cocktails, etc.
- Edamam Food and Grocery Database – The Edamam Food and Grocery Database is an API that allows finding food and nutrition data for generic foods, packaged foods, and restaurant meals. It employs NLP (Natural Language Processing) which allows extraction of food entities from unstructured text.
- MyCookbook.io API – The MyCookbook.io API is an API that allows users to create their own cookbook. Thus, users can use it to parse online recipes and convert them into a structured JSON output.
Summary
So, to summarize, Tasty is a food recipe website with millions of recipes. The Tasty API is an API for Tasty. Thus, it provides REST endpoints that allow searching for a recipe, obtaining a list of recipes, obtaining details of an individual recipe, and much more. In this article, we saw how to connect to the Tasty API using RapidAPI. We also took a look at all the Tasty API endpoints. Finally, we saw how to write code that uses the endpoints in various programming languages.
Leave a Reply