Fast API MCQs with answers Page - 10

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 role of `BaseModel` in FastAPI?

  • (A) Defines database models
  • (B) Provides routing configuration
  • (C) Defines request and response schemas using Pydantic
  • (D) Handles authentication

R

Ravina • 3.96K Points
Extraordinary

Q. How can you enforce numeric range in FastAPI query parameters?

  • (A) range(min, max)
  • (B) Numeric(min=, max=)
  • (C) Query(..., ge=1, le=100)
  • (D) validate(min=1, max=100)

R

Ravina • 3.96K Points
Extraordinary

Q. Which FastAPI component is used to manage middleware?

  • (A) MiddlewareStack
  • (B) MiddlewareManager
  • (C) add_middleware()
  • (D) use_middleware()

R

Ravina • 3.96K Points
Extraordinary

Q. What is the correct way to install all the necessary extras for file upload support in FastAPI?

  • (A) pip install fastapi[files]
  • (B) pip install fastapi[multipart]
  • (C) pip install fastapi[upload]
  • (D) pip install fastapi[all]

R

Ravina • 3.96K Points
Extraordinary

Q. Which statement is true about `UploadFile` in FastAPI?

  • (A) It is read-only
  • (B) It is stored fully in memory
  • (C) It stores the file on disk automatically
  • (D) It is a spooled file-like object allowing async read/write

R

Ravina • 3.96K Points
Extraordinary

Q. Which of the following is a valid media type for JSON responses in FastAPI?

  • (A) application/javascript
  • (B) text/html
  • (C) application/json
  • (D) application/xml

R

Ravina • 3.96K Points
Extraordinary

Q. What does `Depends(get_db)` typically represent in FastAPI?

  • (A) Running background tasks
  • (B) Calling another route
  • (C) Injecting a database session
  • (D) Sending a response header

R

Ravina • 3.96K Points
Extraordinary

Q. How can you restrict FastAPI CORS policy to specific origins?

  • (A) Set CORS-Restrict header
  • (B) Add allowed origins in CORSMiddleware
  • (C) Use allowed_cors parameter in app
  • (D) Set origin_policy in decorator

R

Ravina • 3.96K Points
Extraordinary

Q. How do you return a 404 error from a FastAPI route?

  • (A) raise NotFoundError()
  • (B) raise Error404()
  • (C) raise HTTPException(status_code=404)
  • (D) return 404

R

Ravina • 3.96K Points
Extraordinary

Q. What does FastAPI use to describe request bodies and responses?

  • (A) Flask schema
  • (B) SQLAlchemy models
  • (C) Pydantic models
  • (D) Marshmallow schemas

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