Fast API MCQs with answers Page - 20

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 does `app.openapi()` return?

  • (A) HTML documentation
  • (B) List of routes
  • (C) OpenAPI schema in JSON format
  • (D) Swagger UI HTML page

R

Ravina • 3.96K Points
Extraordinary

Q. What is the correct way to access request headers in a route function?

  • (A) request.headers.get('Header-Name')
  • (B) request.get_header('Header-Name')
  • (C) request.header('Header-Name')
  • (D) request.meta['Header-Name']

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is NOT a valid status constant in FastAPI?

  • (A) status.HTTP_200_OK
  • (B) status.HTTP_404_NOT_FOUND
  • (C) status.HTTP_201_CREATED
  • (D) status.HTTP_999_UNKNOWN

R

Ravina • 3.96K Points
Extraordinary

Q. Which parameter is used to validate a minimum length for a query parameter?

  • (A) min_len
  • (B) length_min
  • (C) min_length
  • (D) validate_min

R

Ravina • 3.96K Points
Extraordinary

Q. Which response class should be used to return an image in FastAPI?

  • (A) ImageResponse
  • (B) FileResponse
  • (C) HTMLResponse
  • (D) JSONResponse

R

Ravina • 3.96K Points
Extraordinary

Q. How do you access form data sent via POST in FastAPI?

  • (A) Using Query()
  • (B) Using Form()
  • (C) Using Body()
  • (D) Using Header()

R

Ravina • 3.96K Points
Extraordinary

Q. Which method is used to define a path operation that accepts a list as input?

  • (A) Use a List type in Query()
  • (B) Use a JSON string
  • (C) Use CSV in query string
  • (D) Use multiple query parameters

R

Ravina • 3.96K Points
Extraordinary

Q. How do you define a regex validation for a path parameter?

  • (A) Using Path(..., pattern='...')
  • (B) Using Path(..., regex='...')
  • (C) Using RegexPath('...')
  • (D) Using pattern parameter in decorator

R

Ravina • 3.96K Points
Extraordinary

Q. Which HTTPException code is used for a forbidden request?

  • (A) 401
  • (B) 403
  • (C) 404
  • (D) 500

R

Ravina • 3.96K Points
Extraordinary

Q. Which method is used to handle startup events in FastAPI?

  • (A) @app.load()
  • (B) @app.init()
  • (C) @app.on_event('startup')
  • (D) @app.on('start')

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