Home - Django REST framework
Django REST framework is a powerful and flexible toolkit for building Web APIs. Some reasons you might want to use REST…
[ HTTP 요청 / 응답 설계 ]
ErrorCode / SuccessCode[ API 구조 설계 ]
- Generic API VIEW
ViewSets[ API Custom ]
Filtering[ 인증 권한 설계 ]
HTTP 요청 / 응답 설계
Response(data, status=None, template_name=None, headers=None, content_type=None)
- data: serialized 된 data
- stauts: django status code 사용
- send_response, ok_response, error_response
- 프론트엔드와 통신
→ Response 형식
API 구조 설계
The mixin classes provide the actions that are used to provide the basic view behavior. Note that the mixin classes provide action methods rather than defining the handler methods, such as
One of the key benefits of class-based views is the way they allow you to compose bits of reusable behavior. REST framework takes advantage of this by providing a number of pre-built views that provide for commonly used patterns.
a type of class-based Views, that does not provide any method handlers.
GenericViewSetclass inherits from
GenericAPIView, and provides the default set of
get_querysetmethods and other generic view base behavior, but does not include any actions by default. In order to use a
GenericViewSetclass you'll override the class and either mixin the required mixin classes, or define the action implementations explicitly.
ModelViewSetclass inherits from
GenericAPIViewand includes implementations for various actions, by mixing in the behavior of the various mixin classes. The actions provided by the
serializer_class[ GenericAPIView의 Attribute 의 Basic Setting ]
The serializer class that should be used for validating and deserializing input, and for serializing output. Typically, you must either set this attribute, or override the
ModelSerializerclass provides a shortcut that lets you automatically create a
Serializerclass with fields that correspond to the Model fields.
ModelSerializerclass is the same as a regular
Serializerclass, except that:
1) It will automatically generate a set of fields for you, based on the model.
2) It will automatically generate validators for the serializer, such as unique_together validators.
3) It includes simple default implementations of
[ django-fillter ]
FilterSet creation can be customized by overriding the following methods on the backend class:
.get_filterset(self, request, queryset, view)
.get_filterset_class(self, view, queryset=None)
.get_filterset_kwargs(self, request, queryset, view)