Fast API MCQs with answers Page - 16

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 the purpose of the `tags` parameter in FastAPI route decorators?

  • (A) To restrict access
  • (B) To categorize endpoints in API docs
  • (C) To define middleware
  • (D) To trigger background tasks

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is used to validate cookies in FastAPI?

  • (A) Cookie()
  • (B) Header()
  • (C) Query()
  • (D) Body()

R

Ravina • 3.96K Points
Extraordinary

Q. Which function in FastAPI is used to read request body as plain text?

  • (A) await request.body()
  • (B) request.get_json()
  • (C) request.plain()
  • (D) request.read_text()

R

Ravina • 3.96K Points
Extraordinary

Q. How can you create dependencies that are only evaluated once per request in FastAPI?

  • (A) use_cache=True in Depends
  • (B) singleton=True
  • (C) cache=True
  • (D) shared=True

R

Ravina • 3.96K Points
Extraordinary

Q. Which command installs FastAPI with all optional dependencies?

  • (A) pip install fastapi[extras]
  • (B) pip install fastapi[all]
  • (C) pip install fastapi[full]
  • (D) pip install fastapi+

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following allows response content to be streamed in FastAPI?

  • (A) StreamContent
  • (B) StreamingResponse
  • (C) FileStream
  • (D) ResponseStream

R

Ravina • 3.96K Points
Extraordinary

Q. Which method is used in FastAPI to test endpoints without an external client?

  • (A) fastapi.Client()
  • (B) APITestClient
  • (C) TestClient
  • (D) HttpTester

R

Ravina • 3.96K Points
Extraordinary

Q. How do you define a required query parameter in FastAPI?

  • (A) By not assigning a default value
  • (B) By setting `required=True`
  • (C) By using `Query(...)`
  • (D) By setting `None` as default

R

Ravina • 3.96K Points
Extraordinary

Q. What happens if a Pydantic model has extra fields not defined in its schema?

  • (A) They are included in the response
  • (B) They are ignored unless `extra='allow'` is used
  • (C) They raise a runtime warning
  • (D) They are converted to null

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is used for file uploads in FastAPI?

  • (A) FileField
  • (B) UploadObject
  • (C) UploadFile
  • (D) FileUpload