Request and Response Structure
Learn about the request and response structure of TheCocktailDB API.
We'll cover the following
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 |
|
Lookup cocktails or ingredients by database IDs |
|
Get a random cocktail recipe |
|
Filter cocktails by ingredients, alcoholic filters, categories, or glass type |
|
List the available categories, glasses, ingredients, or alcoholic filters |
|
Note: The API key
1
afterwww.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.