Filter Meals
Learn how to filter the meals to get lists of specific types of meals.
We'll cover the following
The base URI https://www.themealdb.com/api/json/v1/1/filter.php
provides us the names, IDs, and the link for the images of meals. The information obtained from this endpoint can be used to search for the recipes for the meals.
We use these criteria to filter the meals:
- Categories
- Cuisines
- Ingredients
Note: We use the endpoint discussed in the previous lesson to get all the available categories, cuisines, and ingredients.
Query parameters
We can use the following query parameters with this endpoint:
Parameters | Type | Category | Description |
| string | optional | This parameter is used to filter meals using the categories. |
| string | optional | This parameter provides a list of meals from a specific cuisine. |
| string | optional | This parameter is used to get a list of meals in which a specific ingredient is used. |
Note: We need to use at least one of these parameters with this endpoint. Calling it without any query parameters will return an error.
Filter meals by categories
We use the query parameter c
to get the lists of all available meals that fall in a specific category.
The code below demonstrates how we can get meals for a specific category.
import jsonimport requestsurl=('https://www.themealdb.com/api/json/v1/1/filter.php?c=Seafood')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We’ll get the links for the image of the meals, the database IDs for the meals, and the name of the meals in response.
We can replace Seafood
in line 4 with any other category to get the list of meals that fall under that category.
Filter meals by cuisines
We use the query parameter a
to get the lists of available meals for a specific cuisine.
The code below uses this query parameter with www.themealdb.com/api/json/v1/1/filter.php?
base URL to get meals for a specific cuisine.
import jsonimport requestsurl=('https://www.themealdb.com/api/json/v1/1/filter.php?a=Canadian')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We get the links for the image of the meals, the database IDs for the meals, and the name of the meals in response.
We can replace Canadian
in line 4 with another cuisine to get the list of meals for that cuisine.
Filter meals by ingredients
We use the query parameter i
to get the lists of available meals in which a specific ingredient is used.
The code below shows how to get the list of meals filtered by ingredient.
import jsonimport requestsurl=('https://www.themealdb.com/api/json/v1/1/filter.php?i=Chicken')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We’ll get the links for the image of the meals, the database IDs for the meals, and the name of the meals in response.
We can replace Chicken
in line 4 with another ingredient and get the list of all available meals in which that ingredient is used.