You: "If the change is adding a field, it is not breaking and I ship it in v1.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # ====================================================================== # Q: CTO: "A large B2B customer wants a change in the response format. How do # you do it without breaking the others?" # # You: "If the change is adding a field, it is not breaking and I ship it in v1. # If it changes or removes fields, I release v2 with URL versioning. The # business logic stays shared, only the serializer changes. On v1 I send # Deprecation and Sunset headers, watch the logs to see who still uses it, and # notify them before shutting it down." # ====================================================================== class OrderViewSet(viewsets.ReadOnlyModelViewSet): def get_serializer_class(self): return OrderV2Serializer if self.request.version == 'v2' else OrderV1Serializer def finalize_response(self, request, response, *args, **kwargs): response = super().finalize_response(request, response, *args, **kwargs) if request.version == 'v1': response['Deprecation'] = 'true' response['Sunset'] = 'Wed, 31 Mar 2027 00:00:00 GMT' return response |