Hacker News new | ask | show | jobs
by miketery 1251 days ago
> "Reuse serializers as little as possible" is the single best piece of advice when using DRF. The inline InputSerializer thing is brilliant.

Can you expand on this? What is the InputSerializer as opposed to custom rest serializers?

1 comments

I think the idea is that instead of thinking "here's the object I'm serializing" you should think "here's the view (endpoint) I'm serializing for".

Contrary to what people usually think, the shape of the serialized object is typically defined by the API endpoint, not by the object itself. Different endpoints can (and will) serve different shapes of the same object.

Even if two endpoints serve the same shape today, they can deviate tomorrow. When this happens, most people are trying to resolve it through DRF inheritance, which is wrong.