Cơ BảnFastAPI iconFastAPI

Pydantic model trong FastAPI dùng để làm gì?

Pydantic model định nghĩa schema cho request body, response, settings hoặc object trung gian. FastAPI dùng model để validate input, serialize output và sinh OpenAPI schema.

Model nên tách theo use-case: UserCreate cho input tạo mới, UserRead cho response, UserUpdate cho partial update. Không nên expose trực tiếp database model nếu nó có field nhạy cảm như password hash hoặc internal flags.

Xem toàn bộ FastAPI cùng filter theo level & chủ đề con.

Mở danh sách FastAPI