Search for the Recipe of a Meal

Learn how to use TheMealDB API to search for a meal.

TheMealDB API provides an endpoint to search for the recipe of any meal from the database. We can search for a meal’s recipe using the base URI www.themealdb.com/api/json/v1/1/search.php. We’ll get information about the meal and how we can make it.

Query parameters

We can use these query parameters with this endpoint:

Parameters

Type

Category

Description

s

string

optional

This parameter is used to search for a meal using its name.

f

string

optional

This parameter is used to search for a meal using the first letter of its name.

Note: We need to use at least one of these parameters with this endpoint. Calling it without any query parameters will return an error.

Search meal by the name

We use the query parameter s to search for a meal using its name.

The code below contains the code where a meal is being searched using its name.

Press + to interact
import json
import requests
url=('https://www.themealdb.com/api/json/v1/1/search.php?s=Arrabiata')
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))

We’ll get the following information in response:

  • Ingredients required
  • Instructions to create a meal
  • Amounts of ingredients
  • Name of the meal
  • Database ID
  • Category
  • Cuisine
  • Link for an image of the meal
  • Video
  • Database tags
  • Last modified date
  • License

We can replace Arrabiata in line 4 with the name of other meals if we want the recipe for any other meal.

Search a meal by the first letter of its name

We use query parameter f, with the base URL of the search endpoint, to get a list of meals whose names start with a similar letter. The code below shows how we can use this query parameter.

Press + to interact
import json
import requests
url=('https://www.themealdb.com/api/json/v1/1/search.php?f=a')
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))

We get the same information in response as the first case but for all the meals with the initials a.

We can replace a in line 4 with any other letter to get a different list of meals.