Summary
This release adds support for Pydantic when using the handler dispatcher, similar to what you are used to from FastAPI.
Here is an example:
python
class MyItem(pydantic.BaseModel):
name: str
price: float
is_offer: bool = None
route("/items/<item_id>", methods=["POST"])
def add_item(request: Request, item_id: int, item: MyItem) -> str:
print(item.name, item.price)
return "ok"
route("/items/<item_id>", methods=["GET"])
def get_item(request: Request, item_id: int) -> MyItem:
return MyItem(name="rolo", price=4.20)
You can also use the `resource` decorator on classes to organize your code:
python
router = Router(dispatcher=handler_dispatcher())
resource("/items/<int:item_id>")
class MyResource:
def on_get(self, request: Request, item_id: int):
return MyItem(name="rolo", price=420.69)
def on_post(self, request: Request, item_id: int, item: MyItem):
return {"item_id": item_id, "item": item.model_dump()}
router.add(MyResource())
What's Changed
* add support for pydantic in the handler dispatcher by thrau in https://github.com/localstack/rolo/pull/14
* fix restore payload by bentsku in https://github.com/localstack/rolo/pull/13
New Contributors
* bentsku made their first contribution in https://github.com/localstack/rolo/pull/13
**Full Changelog**: https://github.com/localstack/rolo/compare/v0.5.0...v0.6.0