FastAPI is a relatively new web framework for Python claiming to be one of the fastest Python frameworks available. In this article, I will discuss...
For further actions, you may consider blocking this person and/or reporting abuse
@fuadrafid
Actually to pass validation error message you can just use pydantic
@validator
decorator. For example:Then on validation error this will be the response body:
Thank you for reading!
You are suggesting custom validators, I was talking about the default validators provided by pydantic. These work fine, but image having a project with 50+ dataclasses, writing validators for each of the variables isn't really efficient.
You can see Springboot's validators. A simple message inside the annotation itself, simple and efficient.
Thanks. It's a good read. As mentioned in Cons 2, async/await like Node.js style could be a big advantage in case that the web app is not CPU bounded and needs to deal with a lot of requests dispatching them to backend servers, database and APIs. I am on it.
Hi ! good thoughts
About your last issue..
I'm working on the project django-ninja ( github.com/vitalik/django-ninja ) which also uses Pydantic for validation
And also think on some ways to give users a way to customize validation messages...
Do you have any design in mind ? like how would you prefer to customize validation message and on which layer ?
Hi,
Thank for sharing your work. I think the validation can be incorporated with the dtos with an annotation and validation checks should be at the middleware layer.
I am having the same problem with validations with FastAPI.
Django Rest Framework is doing a great job with this, example:
Did you found any solution for better formating of validation errors in FastAPI?
Hello Mirza,
I haven't really looked into it. But you can look into this GitHub thread:
github.com/tiangolo/fastapi/issues...
Like Takashi Futada commented here—I think the async/await Python keywords is a huge plus for FastAPI, no need for a third-party framework to do asynchronous. My colleague wrote a comparison of the two frameworks that you might find interesting: stxnext.com/blog/fastapi-vs-flask-...
Nice post. I have recently started using FastAPI. I think it will be much better when a stable version of it will be released. Waiting for version 1.0.0 actually. I have high hopes for FastAPI.
Thanks. The future of FastAPI looks good to me too. Happy coding!
[Advertisement warning] regarding con point 2 I wrote a dependency injection framework which works well with fastapi and addresses this point: github.com/meadsteve/lagom
Thanks for sharing your work! It seems feature rich and easy to use. Will try it out in the future.
After all, the performance is a very high value for fastapi... though i am mastered in django, i am learning fastapi instead of flask. I think FastAPI will be better as time goes.
Thank you for reading! Hope it gets better with time.
Although the documentation is good but the resources available for integrating it with other services are very few. Hopefully it will get better with time.
Btw, nice article! :)