Skip to content

Composability question #10

Answered by ElMassimo
aviemet asked this question in Q&A
Apr 4, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hi Avram!

any suggestions for creating seralizers which would change slightly for each view

Typically the way I like to structure them, is to create one serializer per "use case".

For example, you might have a lighter serializer for an index page, and a serializer with more info for a show page.

Because serializers should not typically contain business logic, unless the difference is very simple, I'd typically avoid using inheritance and specify the full list of attributes that are needed upfront.

The benefit of that, is that adding more attributes to one "endpoint" does not accidentally add that unnecessarily to other endpoints, which can be hard to notice (and could affect performance…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@aviemet
Comment options

@ElMassimo
Comment options

Answer selected by aviemet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants