🍓Unit 13: Data Types
Introduction
Besides primitive data types (int
, float
, str
, bool
), user-defined data types, FastAPI also supports advanced data types such as UUID
, datetime
. In this unit, we will delve into the use of these data types within the context of FastAPI.
You can find out all the valid Pydantic data types at https://docs.pydantic.dev/latest/concepts/types/
Extra data types
In the following table, we present additional data types from Pydantic. Because these types are provided by Pydantic, they offer all the useful features, including editor support, data conversion for incoming requests and responses, data validation, and automatic annotation and documentation.
Example program
Let's consider the following program:
In case you don't know how to interact with the program in Postman, you can interact with its API Docs available at http://127.0.0.1:8000/docs and http://127.0.0.1:8000/redoc
Fig. 1 shows how to interact with the program in Postman.
The
generate_uuid()
function can be used to generate a dummy UUID.The value
P3D
inprocess_after
is followed the ISO 8601 format. You can find out more details at https://en.wikipedia.org/wiki/ISO_8601#Durations
Last updated