Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

flask
api
web development
endpoint

How to make a topics API endpoint in Flask

Educative Answers Team

Extending a Flask web application with an API

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.

Topics API endpoint

One of the first steps in developing an API for the application would be to identify the topics on the website.

app.py
topics.py
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"
  ]
}

RELATED TAGS

flask
api
web development
endpoint
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring