From f166c79785d2ad4ae11c31ee9b291d853c9afc47 Mon Sep 17 00:00:00 2001 From: Radoslav Georgiev Date: Sun, 25 Oct 2020 12:14:03 +0200 Subject: [PATCH] Replace the list API example with one from `Styleguide-Example` project --- README.md | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 99b609b..36fb7f6 100644 --- a/README.md +++ b/README.md @@ -382,21 +382,42 @@ Here are few examples: `UserCreateApi`, `UserSendResetPasswordApi`, `UserDeactiv ### An example list API +#### Plain + +A dead-simple list API would look like that: + ```python -class CourseListApi(SomeAuthenticationMixin, APIView): +from rest_framework.views import APIView +from rest_framework import serializers +from rest_framework.response import Response + +from styleguide_example.users.selectors import user_list +from styleguide_example.users.models import BaseUser + + +class UserListApi(APIView): class OutputSerializer(serializers.ModelSerializer): class Meta: - model = Course - fields = ('id', 'name', 'start_date', 'end_date') + model = BaseUser + fields = ( + 'id', + 'email' + ) def get(self, request): - courses = get_courses() + users = user_list() - serializer = self.OutputSerializer(courses, many=True) + data = self.OutputSerializer(users, many=True).data - return Response(serializer.data) + return Response(data) ``` +Keep in mind this API is public by default. Authentication is up to you. + +#### Filters + Pagination + +You can find the code for the example list API with filters & pagination in the [Styleguide Example](https://github.com/HackSoftware/Styleguide-Example#example-list-api) project. + ### An example detail API ```python