Bird
0
0

Given the code snippet:

medium📝 component behavior Q4 of 15
Flask - WebSocket and Real-Time
Given the code snippet:
from flask_restx import Api, Namespace, Resource
from flask import Flask

app = Flask(__name__)
api = Api(app)

ns = Namespace('books', description='Book related operations')

@ns.route('/list')
class BookList(Resource):
    def get(self):
        return {'books': ['Book1', 'Book2']}

api.add_namespace(ns)

if __name__ == '__main__':
    app.run()

What URL path will return the list of books?
A/api/books/list
B/books/list
C/list
D/books
Step-by-Step Solution
Solution:
  1. Step 1: Understand Namespace prefix

    The Namespace 'books' prefixes all routes inside it, so '/list' becomes '/books/list'.
  2. Step 2: Confirm no extra prefix

    Since no API prefix is set, the path is exactly '/books/list'.
  3. Final Answer:

    /books/list -> Option B
  4. Quick Check:

    Namespace prefix + route = /books/list [OK]
Quick Trick: Namespace name prefixes all its routes [OK]
Common Mistakes:
MISTAKES
  • Using route without namespace prefix
  • Assuming /api prefix exists
  • Confusing route with namespace name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes