Fast API MCQs with answers Page - 21

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. Which feature of FastAPI helps with dependency injection?

  • (A) Depends()
  • (B) Inject()
  • (C) Bind()
  • (D) Attach()

R

Ravina • 3.96K Points
Extraordinary

Q. Which response class is used to return raw bytes data in FastAPI?

  • (A) ByteResponse
  • (B) RawResponse
  • (C) Response(content=bytes)
  • (D) BinaryResponse

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following supports declaring file input in FastAPI?

  • (A) File()
  • (B) Path()
  • (C) Header()
  • (D) Upload()

R

Ravina • 3.96K Points
Extraordinary

Q. What does `raise HTTPException(status_code=404, detail='Item not found')` do?

  • (A) Redirects the user
  • (B) Logs a warning
  • (C) Returns a 404 response with JSON error message
  • (D) Crashes the server

R

Ravina • 3.96K Points
Extraordinary

Q. How do you access the full request object in a path operation?

  • (A) Use `req` parameter
  • (B) Use `request: Request` in function parameters
  • (C) Use `context` object
  • (D) Use `args` object

R

Ravina • 3.96K Points
Extraordinary

Q. What happens if a route raises a `ValueError` and no handler is defined?

  • (A) FastAPI auto-converts it to 404
  • (B) FastAPI returns 500 Internal Server Error
  • (C) FastAPI returns 400 Bad Request
  • (D) FastAPI logs and ignores it

R

Ravina • 3.96K Points
Extraordinary

Q. What does `File(..., media_type='image/png')` specify?

  • (A) Only PNG files are allowed
  • (B) Adds description for the API docs
  • (C) Sets the expected content type in API docs
  • (D) Limits the file size

R

Ravina • 3.96K Points
Extraordinary

Q. What happens when FastAPI detects a mismatch in type for a query parameter?

  • (A) It coerces the value
  • (B) It skips validation
  • (C) It raises a 422 Unprocessable Entity error
  • (D) It returns null

R

Ravina • 3.96K Points
Extraordinary

Q. Which of these is true about async support in FastAPI?

  • (A) All route functions must be async
  • (B) Only sync functions are allowed
  • (C) Both async and sync functions are supported
  • (D) Async functions only work with Flask

R

Ravina • 3.96K Points
Extraordinary

Q. Which type of response class is best for returning HTML content in FastAPI?

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

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