'How do I destructure an API with python Django and django-rest-framework?

I have a successfully compiled and run a django rest consuming cocktaildb api. On local server when I run http://127.0.0.1:8000/api/ I get

{
    "ingredients": "http://127.0.0.1:8000/api/ingredients/",
    "drinks": "http://127.0.0.1:8000/api/drinks/",
    "feeling-lucky": "http://127.0.0.1:8000/api/feeling-lucky/"
}

But when I go to one of the links mentioned in the json result above, for example:

http://127.0.0.1:8000/api/ingredients/

I get an empty [] with a status 200OK!

I need an endpoint to GET drinks and ingredients before I can destructure to specific details using angular.

I implemented helper folder in the app with the the API function as below:

class TheCoctailDBAPI:

    THECOCTAILDB_URL = 'https://www.thecocktaildb.com/api/json/v1/1/'

    async def __load_coctails_for_drink(self, drink, session):
        for i in range(1, 16):
            ingredientKey = 'strIngredient' + str(i)
            ingredientName = drink[ingredientKey]

            if not ingredientName:
                break

            if ingredientName not in self.ingredients:
                async with session.get(f'{TheCoctailDBAPI.THECOCTAILDB_URL}search.php?i={ingredientName}') \
                        as response:
                    result = json.loads(await response.text())
                    self.ingredients[ingredientName] = result['ingredients'][0]


Solution 1:[1]

What was your expected responce?

Add the function that is called by this API as well as the DB settings in the question, so that we can properly help you.

Are you sure that you are connecting and pulling data from a remote location? It looks to me like your local DB is empty, so the API has no data to return.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 justhere