In 𝗙𝗮𝘀𝘁𝗔𝗣𝗜, 𝗿𝗲𝘁𝘂𝗿𝗻 𝘁𝘆𝗽𝗲 and 𝗿𝗲𝘀𝗽𝗼𝗻𝘀𝗲_𝗺𝗼𝗱𝗲𝗹 describe the success body: a single Pydantic model, or a list of that model—whatever the handler returns on a normal 2xx. When a lookup fails or a rule is broken, you raise 𝗛𝗧𝗧𝗣𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 so the client gets a proper 𝟰𝘅𝘅 𝘀𝘁𝗮𝘁𝘂𝘀 and a 𝗱𝗲𝘁𝗮𝗶𝗹 𝗽𝗮𝘆𝗹𝗼𝗮𝗱. That is separate from the return type, because raise is not return. 𝗿𝗲𝘀𝗽𝗼𝗻𝘀𝗲_𝗺𝗼𝗱𝗲𝗹 defines how the 𝘀𝘂𝗰𝗰𝗲𝘀𝘀 𝗿𝗲𝘀𝗽𝗼𝗻𝘀𝗲 is built and documented; HTTPException is how you answer with an error without faking a 200. 👉 Detailed breakdown here: https://lnkd.in/gcySJqZX 👉 Code Here: https://lnkd.in/gyf4663s #FastAPI #Python #API #BackendDevelopment #SoftwareEngineering #Pydantic #OpenAPI

To view or add a comment, sign in

Explore content categories