Google News
logo
FastAPI - Quiz(MCQ)

FastAPI : FastAPI is a modern web framework for building RESTful APIs in Python. It was first released in 2018 and has quickly gained popularity among developers due to its ease of use, speed and robustness. FastAPI is based on Pydantic and uses type hints to validate, serialize and deserialize data.

The key features are :

Fast : Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.

Fast to code: Increase the speed to develop features by about 200% to 300%. *

Fewer bugs : Reduce about 40% of human (developer) induced errors. *

Intuitive : Great editor support. Completion everywhere. Less time debugging.

Easy : Designed to be easy to use and learn. Less time reading docs.

Short : Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.

Robust : Get production-ready code. With automatic interactive documentation.

Standards-based : Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.

A)
Java Web framework
B)
Ruby Web framework
C)
Python Web framework
D)
PHP Web framework

Correct Answer :   Python Web framework


Explanation : FastAPI is a modern Python web framework.

A)
Built-in support for SQL databases
B)
Built-in support for machine learning
C)
Built-in support for front-end development
D)
Built-in support for asynchronous programming

Correct Answer :   Built-in support for asynchronous programming


Explanation : FastAPI has built-in support for asynchronous programming, which allows it to handle a large number of concurrent requests without blocking.

A)
Flask
B)
Starlette
C)
Django
D)
None of the above

Correct Answer :   Starlette


Explanation : FastAPI is built on top of Starlette.

A)
Apr 2020
B)
Dec 2018
C)
Jan 2015
D)
May 2012

Correct Answer :   Dec 2018


Explanation : FastAPI was created in December 2018 by Sebastian Ramirez.

A)
It is faster and more efficient
B)
It is easier to learn and use
C)
It has better documentation
D)
It has a larger community of users

Correct Answer :   It is faster and more efficient


Explanation : FastAPI is designed to be fast and efficient, making it a good choice for high-performance applications.

6 .
What is the purpose of the @app.get() decorator in FastAPI?
A)
To define a new database table
B)
To define a new class for handling requests
C)
To define a new route for handling GET requests
D)
To define a new function for handling requests

Correct Answer :   To define a new route for handling GET requests


Explaination : The @app.get() decorator in FastAPI is used to define a new route for handling GET requests.

A)
pip3 install fastapi
B)
pip3 install Starlette-fastapi
C)
pip3 install fastapi- Starlette
D)
None of the above

Correct Answer :   pip3 install fastapi


Explanation : "Pip3 install fastapi" is used to install FastAPI.

A)
Yes
B)
No
C)
Can Not Say
D)
None of the above

Correct Answer :   Yes


Explanation : Since FastAPI relies on the Starlette and Pydantic libraries, these are also installed.

A)
Type Hinting
B)
Annotations
C)
Decorators
D)
None of the above

Correct Answer :   Decorators


Explanation : Decorators are used to specify routes in FastAPI.

A)
CORSMiddleware
B)
TrustedHostMiddleware
C)
HTTPSRedirectMiddleware
D)
All of the above

Correct Answer :   All of the above


Explanation : Following are some of the middleware available in the FastAPI library :

* CORSMiddleware
* TrustedHostMiddleware
* HTTPSRedirectMiddleware
* GZipMiddleware

A)
PathException
B)
HTTPException
C)
RouterException
D)
All of the above

Correct Answer :   HTTPException


Explanation : HTTPException is used to return HTTP replies with problems to the client.

A)
Casing
B)
Coupling
C)
Clamping
D)
Mounting

Correct Answer :   Mounting


Explanation : "Mounting" refers to the addition of a complete "independent" application in a specified route, which subsequently handles all sub-paths.

13 .
Which of the following statement is True?
A)
A response body is data sent by the client to your API. A request body is the data your API sends to the client.
B)
A request body is data sent by the client to your API. A response body is the data your API sends to the client.
C)
Both (A) and (B)
D)
None of the above

Correct Answer :   A request body is data sent by the client to your API. A response body is the data your API sends to the client.

A)
Yes
B)
No
C)
Can Not Say
D)
None of the above

Correct Answer :   Yes


Explanation : Yes, you can use FastAPI to upload files. There are several approaches, but the most typical is to utilize the FileUpload class.

A)
@app.middle_route("http").
B)
@app.middleware_engine("http").
C)
@app.middleware("http")
D)
None of the above

Correct Answer :   @app.middleware("http")


Explanation : To create a middleware you use the decorator @app.middleware("http").

A)
Yes
B)
No
C)
Can Not Say
D)
None of the above

Correct Answer :   No


Explanation : FastAPI doesn't come with any built-in server application.

A)
Unicorn
B)
Umicorn
C)
Uvicorn
D)
Uxicorn

Correct Answer :   Uvicorn


Explanation : To launch the FastAPI application, you'll require an ASGI server named uvicorn.

A)
Application Server Gateway Interface
B)
Application System Gateway Interface
C)
Asynchronous System Gateway Interface
D)
Asynchronous Server Gateway Interface

Correct Answer :   Asynchronous Server Gateway Interface


Explanation : ASGI stands for Asynchronous Server Gateway Interface.

A)
Web Server Gateway Interface
B)
Web Shift Gateway Interface
C)
Web Socket Gateway Interface
D)
None of the above

Correct Answer :   Web Server Gateway Interface


Explanation : WSGI stands for Web Server Gateway Interface.

A)
To provide front-end development tools
B)
To provide serialization and deserialization of data
C)
To provide machine learning functionality
D)
To provide database management functionality

Correct Answer :   To provide serialization and deserialization of data


Explanation : Pydantic is a data validation and serialization library that is used in FastAPI to serialize and deserialize data sent to and from endpoints.

A)
To store database records
B)
To handle incoming requests
C)
To define outgoing responses
D)
To validate request parameters

Correct Answer :   To define outgoing responses


Explanation : The Response class in FastAPI is used to define outgoing responses from an API endpoint.

22 .
What is the purpose of the @app.middleware() decorator in FastAPI?
A)
To define a new database table
B)
To define a new class for handling requests
C)
To define a new route for handling requests
D)
To define a new middleware function for handling requests

Correct Answer :   To define a new middleware function for handling requests


Explaination : The @app.middleware() decorator in FastAPI is used to define a new middleware function for handling requests.

23 .
Which of the following is a valid FastAPI dependency definition?
A)
def my_dependency():
pass
B)
class MyDependency:
pass
C)
@app.dependency()
def my_dependency():
pass
D)
@app.dependency()
class MyDependency:
pass

Correct Answer :  

@app.dependency()
class MyDependency:
pass


Explaination : Is a valid FastAPI dependency definition, which defines a class decorated with ‘@app.dependency()’.

24 .
A ____ is the section of the URL that comes after the initial '/'.
A)
Unit
B)
Route
C)
Channel
D)
None of the above

Correct Answer :   Route


Explaination : A path or route is the section of the URL that comes after the initial '/'.

A)
Asyn
B)
Async
C)
Asyncho
D)
All of the above

Correct Answer :   Async


Explanation : The async keyword in the function's definition tells FastAPI that it is to be run asynchronously.

A)
Path class
B)
Validate class
C)
Validation class
D)
Parameter class

Correct Answer :   Path class


Explanation : You must import the Path class in order to apply the validation requirements to a path argument.

A)
PyOpe
B)
Schema
C)
Pydantic
D)
Marshmello

Correct Answer :   Pydantic


Explanation : Pydantic is a Python data parsing and validation library.

A)
True
B)
False
C)
Can Not Say
D)
None of the above

Correct Answer :   True


Explanation : Pydantic will convert data types automatically whenever feasible.

A)
CSV
B)
CSS
C)
HTML
D)
JSON

Correct Answer :   JSON


Explanation : FastAPI sends a JSON response to the client by default.

A)
To define a database schema
B)
To handle incoming requests
C)
To validate request parameters
D)
To provide shared functionality between endpoints

Correct Answer :   To provide shared functionality between endpoints


Explanation : A FastAPI dependency is used to provide shared functionality between endpoints, such as authentication, authorization, or database connections.

31 .
Which of the following is an example of a FastAPI path operation decorator?
A)
@app.middleware()
def my_middleware(request, response):
pass
B)
@app.get(‘/users’)
def get_users():
pass
C)
@app.dependency()
def my_dependency():
pass
D)
@app.post(‘/users’)
def create_user(user: dict):
pass

Correct Answer :  

@app.get(‘/users’)
def get_users():
pass


Explaination : Is an example of a FastAPI path operation decorator, which decorates a function with a HTTP method and a path.

A)
PUT
B)
POST
C)
PATCH
D)
All of the above

Correct Answer :   All of the above


Explanation : FastAPI supports all of the above HTTP methods for path operation decorators, as well as GET and DELETE.

A)
@app.getter()
B)
@app.get()
C)
@app.get_request()
D)
None of the above

Correct Answer :   @app.get()


Explanation : @app.get() is a decorator for defining a route or endpoint that handles GET requests.

34 .
Which of the following is a decorator used to specify a FastAPI route or endpoint? It is used to link a function to a certain HTTP request method (such as GET, POST, PUT, DELETE, and so on) and URL path.
A)
@app.route()
B)
@app.router()
C)
@app.route_engine()
D)
All of the above

Correct Answer :   @app.route()


Explaination : @app.route() is a decorator used to specify a FastAPI route or endpoint. It is used to link a function to a certain HTTP request method (such as GET, POST, PUT, DELETE, and so on) and URL path.

A)
Sockets class
B)
Web class
C)
WebSockets class
D)
WebGL class

Correct Answer :   WebSockets class


Explanation : WebSockets are supported by FastAPI via the WebSocket class in the FastAPI module.

A)
Yes
B)
No
C)
Can Not Say
D)
None of the above

Correct Answer :   Yes


Explanation : Yes, FastAPI supports asynchronous requests, which can help your application run better.

A)
One of HTTP's disadvantages is that it is just a full-duplex or directional protocol.
B)
One of HTTP's disadvantages is that it is just a half-duplex or unidirectional protocol.
C)
Both (A) and (B)
D)
None of the above

Correct Answer :   One of HTTP's disadvantages is that it is just a half-duplex or unidirectional protocol.


Explanation : One of HTTP's disadvantages is that it is just a half-duplex or unidirectional protocol.

38 .
A ____ is a persistent connection that allows bidirectional, full-duplex communication between a client and a server.
A)
WebGL
B)
Web Servlet
C)
WebSocket
D)
None of the above

Correct Answer :   WebSocket


Explaination : A WebSocket is a persistent connection that allows bidirectional, full-duplex communication between a client and a server.

A)
Yes
B)
No
C)
Can Not Say
D)
None of the above

Correct Answer :   Yes


Explanation : FastAPI can also leverage NoSQL databases like MongoDB, Cassandra, CouchDB, and others as the backend for REST app CRUD operations.

40 .
______ is a programming technique for converting data between incompatible type systems in object-oriented programming languages.
A)
AOP
B)
OOP
C)
ORM
D)
Functional programming

Correct Answer :   ORM


Explaination : Object Relational Mapping is a programming technique for converting data between incompatible type systems in object-oriented programming languages.

A)
Combine-Origin Resource Sharing
B)
Combine-Origin Resource System
C)
Both (A) and (B)
D)
Cross-Origin Resource Sharing

Correct Answer :   Cross-Origin Resource Sharing


Explanation : CORS stands for Cross-Origin Resource Sharing.

A)
FORM CLASS
B)
HTML CLASS
C)
HTML-FORM CLASS
D)
None of the above

Correct Answer :   FORM CLASS


Explanation : FastAPI has a Form class to process the data received as a request by submitting an HTML form.

43 .
Which of the following is a valid FastAPI response header definition?
A)
@app.get(‘/users/{id}’)
def get_user(id: int):
return {‘X-Total-Count’: 10}
B)
@app.post(‘/users’)
def create_user(user: dict):
return {‘X-Total-Count’: 10}
C)
@app.put(‘/users/{id}’)
def update_user(id: int, user: dict):
return {‘X-Total-Count’: 10}
D)
None of the above

Correct Answer :  

@app.get(‘/users/{id}’)
def get_user(id: int):
return {‘X-Total-Count’: 10}


Explaination : Is a valid FastAPI response header definition, which sets a custom header in the response using a dictionary.

44 .
Which of the following is a valid FastAPI exception handler?
A)
@app.middleware()
def handle_exception(request, response, exc):
pass
B)
@app.middleware(‘http’)
def handle_http_exception(request, response, exc):
pass
C)
@app.exception_handler(HTTPException)
def handle_http_exception(request, exc):
pass
D)
@app.exception_handler(ValueError)
def handle_value_error(request, exc):
pass

Correct Answer :  

@app.exception_handler(ValueError)
def handle_value_error(request, exc):
pass


Explaination : Is a valid FastAPI exception handler, which handles exceptions of a specific type using a decorator on a function that accepts the request and the exception object.

A)
Coupling
B)
Dependency injection
C)
Refactoring dependency
D)
None of the above

Correct Answer :   Dependency injection


Explanation : Dependency injection is the process through which an item obtains other objects on which it depends.

A)
Reuse shared functionality
B)
Share database connections
C)
Authentication and security requirements.
D)
All of the above

Correct Answer :   All of the above


Explanation : Following are the advantages of dependency injection :

* Reuse shared functionality
* Share database connections
* Authentication and security requirements

47 .
Which of the following is a valid FastAPI middleware?
A)
@app.get(‘/users’)
def get_users():
pass
B)
@app.post(‘/users’)
def create_user(user: dict):
pass
C)
@app.middleware()
def my_middleware(request, response):
pass
D)
@app.exception_handler(ValueError)
def handle_value_error(request, exc):
pass

Correct Answer :  

@app.middleware()
def my_middleware(request, response):
pass


Explaination : Is a valid FastAPI middleware, which intercepts requests and responses in the application and can modify them or perform additional operations.