Fast API MCQs with answers Page - 19

Here, you will find a collection of MCQ questions on Fast API. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

R

Ravina • 3.96K Points
Extraordinary

Q. What is required to use OAuth2PasswordBearer in FastAPI?

  • (A) Session token
  • (B) Bearer token in Authorization header
  • (C) Cookie-based auth
  • (D) Basic authentication

R

Ravina • 3.96K Points
Extraordinary

Q. How does FastAPI return JSON responses by default?

  • (A) Using Flask jsonify
  • (B) Using `json.dumps()`
  • (C) Using `JSONResponse`
  • (D) Using `jsonify` from starlette

R

Ravina • 3.96K Points
Extraordinary

Q. Which of these is true about Pydantic’s `Field()` in FastAPI?

  • (A) Used only for path parameters
  • (B) Used only with file uploads
  • (C) Adds metadata and validation for model fields
  • (D) Restricts to integers only

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is used to define headers in FastAPI route function?

  • (A) Header()
  • (B) Request.headers
  • (C) Context()
  • (D) Env()

R

Ravina • 3.96K Points
Extraordinary

Q. What does `status.HTTP_401_UNAUTHORIZED` represent?

  • (A) OK
  • (B) Unauthorized
  • (C) Not Found
  • (D) Internal Server Error

R

Ravina • 3.96K Points
Extraordinary

Q. Which built-in route serves ReDoc UI in FastAPI?

  • (A) /redoc
  • (B) /docs/redoc
  • (C) /openapi/redoc
  • (D) /ui

R

Ravina • 3.96K Points
Extraordinary

Q. How can you define global dependencies for all routes in FastAPI?

  • (A) Using `Depends()` on each function
  • (B) Using `app.add_dependency()`
  • (C) Passing `dependencies` list to FastAPI constructor
  • (D) Using `global_dependencies()`

R

Ravina • 3.96K Points
Extraordinary

Q. What is the behavior of FastAPI when you define an endpoint with the same path and method?

  • (A) Overrides the previous one
  • (B) Raises a duplicate route error
  • (C) Randomly chooses one
  • (D) Both get registered

R

Ravina • 3.96K Points
Extraordinary

Q. How can you disable Swagger UI in FastAPI?

  • (A) Set `docs_url=None` in FastAPI()
  • (B) Call `app.disable_docs()`
  • (C) Use `disable_ui=True`
  • (D) Remove all GET routes

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is true about FastAPI's automatic documentation?

  • (A) It requires manual Swagger configuration
  • (B) It is disabled by default
  • (C) It is powered by OpenAPI and Swagger UI
  • (D) It only works for GET methods

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ