Skip to content

APIView

Base APIView classes with serializer and pagination helpers. See the APIView guide for the dispatch loop and helper method surface.

APIView

Bases: APIViewHelpersMixin, APIView

DRF APIView plus restflow response and serializer helpers.

Sync view base. Use restflow.views.AsyncAPIView for async dispatch.

class UserView(APIView):
    serializer_class = UserSer
    pagination_class = PageNumberPagination

    def get(self, request):
        return self.paginated_response(User.objects.all())

    def post(self, request):
        ser = self.validated_serializer()
        user = ser.save()
        return self.serialized_response(user, status=201)

AsyncAPIView

Bases: APIViewHelpersMixin, APIView

APIView whose dispatch loop is async.

Adds an async dispatch and a*-prefixed surface (ainitial, ahandle_exception, avalidated_serializer, aserialized_response, apaginated_response) on top of DRF's APIView.

dispatch async

dispatch(request, *args, **kwargs)

Async equivalent of APIView.dispatch.

ainitial async

ainitial(request, *args, **kwargs)

Runs anything that needs to occur prior to calling the method handler.

aperform_authentication async

aperform_authentication(request)

Performs authentication on the incoming request.

acheck_permissions async

acheck_permissions(request)

Checks if the request should be permitted, raising on failure.

acheck_object_permissions async

acheck_object_permissions(request, obj)

Checks if the request should be permitted for a given object.

acheck_throttles async

acheck_throttles(request)

Checks the throttles on the incoming request.

ahandle_exception async

ahandle_exception(exc)

Handles any exception that occurs, by returning an appropriate response, or re-raising the error.

afinalize_response async

afinalize_response(request, response, *args, **kwargs)

Returns the final response object after any processing.

avalidated_serializer async

avalidated_serializer(
    *, data=None, serializer_class=None, **kwargs
)

Returns a serializer with the request data validated, awaiting ais_valid when available.

aserialized_response async

aserialized_response(
    instance,
    *,
    many=False,
    status=status.HTTP_200_OK,
    serializer_class=None,
    post_fetches=None,
    headers=None,
)

Returns a Response containing the serialized instance, awaiting any post-fetch helpers.

apaginated_response async

apaginated_response(
    queryset,
    *,
    serializer_class=None,
    pagination_class=None,
    post_fetches=None,
    headers=None,
)

Returns a paginated Response for the given queryset, using async paginator hooks when available.