Skip to content
Advertisement

Partial update in FastAPI

I want to implement a put or patch request in FastAPI that supports partial update. The official documentation is really confusing and I can’t figure out how to do the request. (I don’t know that items is in the documentation since my data will be passed with request’s body, not a hard-coded dict).

JavaScript

How can I complete my code to get a successful partial update here?

Advertisement

Answer

I got this answer on the FastAPI’s Github issues.

You could make the fields Optional on the base class and create a new QuestionCreate model that extends the QuestionSchema. As an example:

JavaScript

The cookiecutter template here provides some good insight too.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement