Fetch Available Listings
Learn how to get the lists of available categories, cuisines, and ingredients available in the database.
We'll cover the following
TheMealDB API provides a variety of filters that we may use to filter the available meals. In this lesson, we’ll look at how to retrieve the listings whose values we can use to filter the meals.
Retrieve lists
We get the lists of items we can use to filter the meals using the base URI, https://www.themealdb.com/api/json/v1/1/list.php
.
This endpoint provides three types of lists, which are as follows:
- Categories list
- Cuisines list
- Ingredients list
Request parameters
We can use any one of the following query parameters with this endpoint:
Parameters | Type | Category | Description |
| String | Optional | Used to get all available categories in the response |
| String | Optional | Used to get the list of available cuisines |
| String | Optional | Used to get all the available ingredients from the database |
Note: We need to use at least one of these parameters with this endpoint. If we call it without any query parameters, it will return an error.
The query parameter c
is used to get the list of available categories. The value assigned to c
will be list
. The widget below contains the code which fetches this list.
const endpointUrl = new URL('https://www.themealdb.com/api/json/v1/1/list.php');const queryParameters = new URLSearchParams({c: 'list'});const options = {method: 'GET'};async function fetchLists() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);printResponse(response);}catch (error) {printError(error);}}fetchLists();
A brief explanation of the above code is given below:
- Line 1: We define the URL of the endpoint.
- Lines 3–9: We define the query parameter and HTTP request type to call the endpoint.
- Lines 11–21: We define the
fetchLists()
function that calls the endpoint and prints the response. - Line 23: We call the
fetchLists()
function.
We can get the list of available cuisines by replacing query parameter, c
, in line 4 with a
.
Similarly, if we replace c
in line 4 with i
, we’ll get the list of available ingredients in response. We can use the list of ingredients we get in response to filter the available meals based on the ingredients.
Response fields
The table below contains some important response fields provided by this endpoint:
Response field | Associated query parameter | Type | Description |
|
| String | The name of the category, which can be used to filter specific types of meals |
|
| String | The available cuisines |
|
| Integer | The API-assigned ID of the ingredient |
|
| String | The name of the ingredient provided by the API |
|
| String | Information about the ingredient |