Request and Response Structure

Learn about the request and response structure of TheCocktailDB API.

Request structure

The request for TheCocktailDB API contains the endpoint the user wants to call. Each endpoint serves a different function. Here is a list of the base URLs which can be used:

Function

Base URI

Search cocktails by ingredient, first letter, or name

www.thecocktaildb.com/api/json/v1/1/search.php

Lookup cocktails or ingredients by database IDs

www.thecocktaildb.com/api/json/v1/1/lookup.php

Get a random cocktail recipe

www.thecocktaildb.com/api/json/v1/1/random.php

Filter cocktails by ingredients, alcoholic filters, categories, or glass type

www.thecocktaildb.com/api/json/v1/1/filter.php

List the available categories, glasses, ingredients, or alcoholic filters

www.thecocktaildb.com/api/json/v1/1/list.php

Note: The API key 1 after www.thecocktaildb.com/api/json/v1/ in each of these addresses is the development API that we talked about in the previous lesson.

These base URIs are combined with the query parameters to get the data we want.

Response structure

The response structure will differ depending on whether our search criteria matched any cocktail from the database or not.

In case of an unsuccessful request

If our search criteria don’t match any drink in the database, the result will contain only one element, drinks or ingredients, depending on whether the search was related to drinks or ingredients. The value of the returned object will be null.

In case of a successful request

For a successful request, we’ll get different data for different endpoints. We’ll discuss the results of successful requests for these endpoints in detail in the upcoming lessons.