Generics & Mixins: Flexible ViewSet Architecture in FastAPI Mason¶
FastAPI Mason's architecture leverages generics and mixins to create flexible, reusable ViewSet components. This modular design enables you to build powerful and customizable APIs by composing specific functionalities tailored to your application’s needs.
Architecture Overview¶
FastAPI Mason uses a layered architecture:
GenericViewSet - The Foundation¶
GenericViewSet
contains all the core business logic:
- Schema handling - Converting between models and Pydantic schemas
- Permission checking - Applying access control
- State management - Managing request context
- Response formatting - Applying wrappers and pagination
Mixins - Route Providers¶
Mixins only add specific routes to the GenericViewSet. They contain no business logic:
ListMixin
- AddsGET /resources/
endpointRetrieveMixin
- AddsGET /resources/{item_id}/
endpointCreateMixin
- AddsPOST /resources/
endpointUpdateMixin
- AddsPUT /resources/{item_id}/
endpointDestroyMixin
- AddsDELETE /resources/{item_id}/
endpoint