From efa24c19dbdb65a84b0f3f4a3e5741174209e6fb Mon Sep 17 00:00:00 2001 From: Ventsislav Tashev Date: Sun, 27 Oct 2019 10:29:13 +0200 Subject: [PATCH 1/2] Fixed List & Detail API serializer signatures --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 44d7a69..5b03fa7 100644 --- a/README.md +++ b/README.md @@ -335,9 +335,9 @@ class CourseListApi(SomeAuthenticationMixin, APIView): def get(self, request): courses = get_courses() - data = self.OutputSerializer(courses, many=True) + serializer = self.OutputSerializer(courses, many=True) - return Response(data) + return Response(serializer.data) ``` ### An example detail API @@ -352,9 +352,9 @@ class CourseDetailApi(SomeAuthenticationMixin, APIView): def get(self, request, course_id): course = get_course(id=course_id) - data = self.OutputSerializer(course) + serializer = self.OutputSerializer(course) - return Response(data) + return Response(serializer.data) ``` ### An example create API From 7459031e1c19cab5b788e506510a490ca8f734e1 Mon Sep 17 00:00:00 2001 From: Ventsislav Tashev Date: Sun, 27 Oct 2019 10:29:49 +0200 Subject: [PATCH 2/2] Removed trailing whitespaces --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b03fa7..dde4c7a 100644 --- a/README.md +++ b/README.md @@ -414,7 +414,7 @@ The implementation of `inline_serializer` can be found in `utils.py` in this rep Now we have separation between our HTTP interface & the core logic of our application. -In order to keep this separation of concerns, our services and selectors must not use the `rest_framework.exception` classes because they are bounded with HTTP status codes. +In order to keep this separation of concerns, our services and selectors must not use the `rest_framework.exception` classes because they are bounded with HTTP status codes. Our services and selectors must use one of: @@ -503,7 +503,7 @@ def get_error_message(exc): return error_msg ``` -You can move this code to a mixin and use it in every API to prevent code duplication. +You can move this code to a mixin and use it in every API to prevent code duplication. We call this `ExceptionHandlerMixin`. Here's a sample implementation from one of our projects: