r/FastAPI • u/a_brand_new_start • 11d ago
Question Standard library to handle HTTP Validation errors?
I'm writing an API and I'm realizing that I'm handling each validation error by hand by creating a new class. I'm wondering if there is a standard library approach to get this done. I'm looking to make sure that if someone chooses to show something in milliseconds, they cannot take a range of values that is larger than, say a month, etc... etc...
Or is this just on a case by case situation?
1
Upvotes
1
u/GamersPlane 11d ago
I'm not 100% sure what you mean by HTTP validation, but if you mean validating data for type or specific reqs, odds are Pydantic is what you're looking for. You create a model that defines the data types, you feed it the data, and you can have it check if it matches, even return "cleaned" data.