REST API request payload validator as a decorator|Sammy Wen|PyCon APAC 2022
PyCon Taiwan
PyCon APAC 2022|一般演講 Talks|國泰金控 Cathay Financial Holdings / 美光科技 Micron 冠名贊助
✏️ 共筆 Note:https://hackmd.io/@pycontw/HkrTI6XJo 🖐🏻 Slido:https://app.sli.do/event/ez4eKwjekuNrwQbbDmEjL9 🪧 投影片 Slides:https://drive.google.com/file/d/1WMPMgOp6mpLTZf-U_abGfDRLCTCc-ois/view?usp=sharing 💬 語言 Language:英文 English 🎯 層級 Level:中階 Intermediate 🔎 分類 Category:Python 核心 Python Core
💡 摘要 Abstract 💡 Developers often mess up the validation steps of the payloads from API requests. Following a systematic way to setup the validator and keep code clean is crucial. A decorator is a function that takes another function as an argument and extends its behavior without explicitly modifying it. Validator-as-a-decorator is an ideal approach for function-based APIs since the validation always happens before the API call happens. It is also reusable and prevent the need of changing the API implementation itself. In this talk, I'll first use a Flask (web framework) + Cerberus (3rd-party data validation library) example to demo the steps of building a Validator-as-a-decorator. The other part of the talk, I'll compare different data validation library in both functionality and restriction aspects, also briefly mention how other web frameworks (Django/FastAPI) deal with request payload validation.
🪄 說明 Description 🪄 Here are the data validation libraries would be mentioned in this talk:
- [Cerberus] https://docs.python-cerberus.org/en/stable/
- [jsonschema] https://python-jsonschema.readthedocs.io/en/stable/
References on how other web frameworks deal with request payload validation:
- [Data spec validator for Django] https://github.com/hardcoretech/data-spec-validator
- [Pydantic and how it's used by FastAPI] https://fastapi.tiangolo.com/tutorial/body/
🚀 講者介紹 About Speaker - Sammy Wen 🚀 Software Engineer II @ Nylas. Currently in Vancouver, BC, Canada. My 5-year journey in Python is awesome! So glad to see the community keeps growing!
#pycontw #pyconapac2022 #python #restapi #flask #cerberus
Follow “PyCon Taiwan” ⭐️ Official Website: https://tw.pycon.org ⭐️ Facebook: https://www.facebook.com/pycontw ⭐️ Instagram: https://www.instagram.com/pycontw ⭐️ Twitter: https://twitter.com/PyConTW ⭐️ LinkedIn: https://www.linkedin.com/company/pycontw ⭐️ Blogger: https://pycontw.blogspot.com ... https://www.youtube.com/watch?v=JLbv10YJSPU
72483261 Bytes