Filter Cocktails
Learn how to filter the cocktails to get lists of specific types of cocktail.
The base URI https://www.thecocktaildb.com/api/json/v1/1/filter.php
provides us the names, IDs, and the link for the image of cocktails. The information obtained from this endpoint can be used to search for the recipes for various cocktails.
We use any of the following four filters to get this information:
- Category of cocktail
- Type of glass
- Ingredients used
- Alcohol content
Note: We can use the endpoint discussed in the previous lesson to get the input data for this endpoint.
Query parameters
We can use any one of the following query parameters with this endpoint:
Parameters | Type | Category | Description |
| string | optional | This parameter is used to filter cocktails using the category. |
| string | optional | This parameter is used to get the list of cocktails served in the specified type of glass. |
| string | optional | This parameter provides a list of cocktails based on whether the cocktails are alcoholic or not. |
| string | optional | This parameter is used to get a list of cocktails 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 cocktails by categories
We use the query parameter c
to get the lists of all available cocktails that fall in a specific category.
The code below demonstrates how we can get cocktails for a specific category.
import jsonimport requestsurl=('https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Ordinary_Drink')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We get the link for the image, database IDs, and names of all ordinary drinks.
We can replace Ordinary_Drink
in line 4 with any other category to get the list of cocktails that fall in that category.
Filter cocktails by glasses
We use the query parameter g
to get the lists of all available cocktails served in a specific type of glass.
The code below demonstrates how we can get the list of cocktails based on the type of glasses the cocktails are served in.
import jsonimport requestsurl=('https://www.thecocktaildb.com/api/json/v1/1/filter.php?g=Champagne_flute')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We’ll get the link for the image, database IDs, and names of all the drinks served in the Champagne flute.
We can replace Champage_flute
in line 4 with any other glass to get a different list.
Filter cocktails by ingredients
We use the query parameter i
to get cocktails based on the ingredients used.
The code below uses this query parameter with the www.thecocktaildb.com/api/json/v1/1/filter.php?
base URL to get cocktails based on the ingredients used.
import jsonimport requestsurl=('https://www.thecocktaildb.com/api/json/v1/1/filter.php?i=Gin')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We’ll get the link for the image, database IDs, and names of all the drinks in which Gin
is used.
We can replace Gin
in line 4 with any other ingredient to get a list of the cocktails in which that ingredient is used.
Filter cocktails by alcoholic filter
We use the query parameter a
to get cocktails based on the alcoholic filters.
The code below provides us with all the available alcoholic drinks.
import jsonimport requestsurl=('https://www.thecocktaildb.com/api/json/v1/1/filter.php?a=Alcoholic')response = requests.request("GET", url).json()print(json.dumps(response, indent=4))
We’ll get the link for the image, database IDs, and names of all the alcoholic drinks.
We can replace Alcoholic
in line 4 with Non_alcoholic
to get the list of non-alcoholic drinks.