Hyperlinks for pydantic models
In a typical web application relationships between resources are modeled by
primary and foreign keys in a database (integers, UUIDs etc.). The most natural
way to represent relationships in REST APIs is by URLs to the related resources
(explained in this blog).
hrefs makes it easy to add hyperlinks between pydantic models in a declarative way. Just
Href field and the library will automatically convert between keys
details_view = "get_book"
# Will produce something like:
hrefs was written especially with FastAPI
in mind, but integrates to any application or framework using pydantic to parse
and serialize models.
Check out the documentation to get started!
Install the library using
pip or your favorite package management tool: