FastAPI Flashcards
What FastAPI uses behind the scenes to check type validation?
Pydantic
What is an Enum in FastAPI?
An Enum in FastAPI is a symbolic name for a set of values, which can be used to define a limited set of valid options for parameters.
True or False: Enums can be used in FastAPI path parameters to enforce valid input values.
True
Fill in the blank: Enums in FastAPI can be defined using the _______ module from the Python standard library.
enum
Which of the following is a valid way to define an Enum in FastAPI? A) class MyEnum(Enum): A = ‘value1’ B) my_enum = Enum(‘MyEnum’, ‘value1 value2’) C) Both A and B
C
How do you specify an Enum as a path parameter in FastAPI?
By using the Enum type as the type hint for the path parameter in the route function.
What HTTP status code indicates a successful request in FastAPI?
200 OK
True or False: In FastAPI, you can set a custom status code in the response using the ‘status_code’ parameter.
True
Fill in the blank: To return a ‘404 Not Found’ status in FastAPI, you can use the response model and set the status code with ______.
status.HTTP_404_NOT_FOUND
Which FastAPI function is used to create a response with a specific status code?
JSONResponse
What is the correct way to return a ‘201 Created’ status when creating a new resource in FastAPI?
return JSONResponse(content={‘message’: ‘Resource created’}, status_code=status.HTTP_201_CREATED)
What is the primary purpose of tags in FastAPI?
To group and organize API endpoints for better documentation and usability.
True or False: Tags in FastAPI can only be applied to functions and not to classes.
False
Fill in the blank: In FastAPI, you can assign tags to an endpoint using the ______ parameter.
tags
Which of the following is a correct way to define tags for an endpoint in FastAPI?
A) tags=[‘user’]
B) tag=’user’
C) tags=’user’
D) tag=[‘user’]
A) tags=[‘user’]
What effect do tags have on the generated OpenAPI documentation in FastAPI?
Tags help organize the endpoints into sections, making the documentation clearer and easier to navigate.
What is FastAPI primarily used for?
FastAPI is primarily used for building APIs with Python.
True or False: FastAPI automatically validates request and response data.
True
Fill in the blank: FastAPI is based on __________ and uses standard Python type hints.
Starlette
Which feature of FastAPI helps in automatic generation of API documentation?
OpenAPI
What is the primary benefit of using FastAPI over other frameworks?
FastAPI offers high performance and easy-to-use features like automatic data validation and interactive documentation.
What is the purpose of the summary feature in FastAPI?
The summary feature provides a brief description of the endpoint’s functionality in the generated API documentation.
True or False: The description feature in FastAPI can be used to provide detailed information about an endpoint.
True
Fill in the blank: In FastAPI, the summary and description can be added to an endpoint using the parameters ______ and ______.
summary, description