Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

web development

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.
topics = {
    "workout_avice" : [...],
    "supplements" : [...],
    "diet_advice" : [...]

This topics_request() method will be added to the 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 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": [


web development
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring