Fast API MCQs with answers Page - 6

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.59K Points
Extraordinary

Q. Which keyword is used in FastAPI to define optional parameters?

  • (A) Maybe
  • (B) Optional
  • (C) Nullable
  • (D) Option

R

Ravina • 3.59K Points
Extraordinary

Q. What is the correct way to make a parameter optional with a default value in FastAPI?

  • (A) def read_item(id: int = None)
  • (B) def read_item(id: Optional[int] = None)
  • (C) def read_item(Optional id: int)
  • (D) def read_item(id?: int)

R

Ravina • 3.59K Points
Extraordinary

Q. How can FastAPI validate the length of a query parameter?

  • (A) Using Query(min_length=3)
  • (B) Using Length(min=3)
  • (C) Using len()
  • (D) Using Validator()

R

Ravina • 3.59K Points
Extraordinary

Q. Which FastAPI feature is used to restrict input values to certain choices?

  • (A) Choice()
  • (B) Enum
  • (C) Validator
  • (D) Limiter

R

Ravina • 3.59K Points
Extraordinary

Q. How do you define a sub-application in FastAPI?

  • (A) Using FastAPI.mount()
  • (B) Using app.include_sub()
  • (C) Using add_subapp()
  • (D) Using route_tree()

R

Ravina • 3.59K Points
Extraordinary

Q. What will `from fastapi import Depends` do?

  • (A) Start the application
  • (B) Allow using templates
  • (C) Enable dependency injection
  • (D) Include static files

R

Ravina • 3.59K Points
Extraordinary

Q. How do you set a custom response header in FastAPI?

  • (A) By editing request.headers
  • (B) Using response.headers['key'] = 'value'
  • (C) Using HeaderResponse
  • (D) Using Header.set()

R

Ravina • 3.59K Points
Extraordinary

Q. Which decorator should you use to create a GET route in FastAPI?

  • (A) @get
  • (B) @app.route(method='GET')
  • (C) @app.get()
  • (D) @app.GET()

R

Ravina • 3.59K Points
Extraordinary

Q. In FastAPI, how can you handle file uploads?

  • (A) Using Upload()
  • (B) Using File()
  • (C) Using FormFile()
  • (D) Using Data()

R

Ravina • 3.59K Points
Extraordinary

Q. What type does FastAPI expect uploaded files to be?

  • (A) str
  • (B) int
  • (C) UploadFile
  • (D) FileStream

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