Let’s assume that a Flask web application exists for which an API is needed. For the sake of this tutorial, we will assume the website is about fitness.
One of the first steps in developing an API for the application would be to identify the topics on the website.
topics = {"workout_avice" : [...],"supplements" : [...],"diet_advice" : [...]}
This topics_request()
method will be added to the app.py
file. Whenever the API makes a GET
request to the /api/topics
path, the topics_request()
will be called to return the required data.
The actual topics will be stored in the topics.py
file as Python dictionary**. This dictionary’s keys will be the names of the topics, the values will be decided by the developers. These values may potentially be the file names and other metadata for the articles in the topics.
The returned data will be a JSON object, like the one shown below.
{"response": 200,"results": ["workout_advice","supplements","diet_advice"]}
Free Resources