Django REST framework는 API endpoints를 만드는데 필요한 두 개의 helper classes를 제공한다.
APIView와 ViewSet이 그것이다. 앞서서 APIView를 다뤘고 여기서는 ViewSet을 다룬다.
1. What is a Viewset?
2. Create a simple Viewset
3. Add create, retrieve, update, partial_update and destroy functions
1. What is a Viewset?
HTTP methods에 mapping되는 함수를 정의하는 대신에, common API object actions에 mapping 되는 몇개의 functions을 받아들인다.
- def list: Getting a list of objects
- def create: Creating new objects
- def retrieve: Getting a specific object
- def update: Updating an object
- def partial_update: Updating part of an object
- def destroy: Deleting an object
<APIView와의 차이>

따라서 standard database operations을 사용하는 상황에 좋고, database back-end와 interface하는 api를 만드는 가장 빠른 방법이기도 하다. 그런 예시들은 다음과 같다.
- performing simple CRUD interface to database
- managing predefined objects
- little to no customization to viewsets provided by Django REST Framework
- working with standard database structures
2. Create a simple Viewset

3. Add create, retrieve, update, partial_update and destroy functions

'BE > Python & Django REST API' 카테고리의 다른 글
| [Django REST API] 11. Create login API (0) | 2021.12.24 |
|---|---|
| [Django REST API] 10. Create Profiles API (0) | 2021.12.22 |
| [Django REST API] 8. Introduction to API Views (0) | 2021.12.18 |
| [Django REST API] 7. Setup Django Admin (0) | 2021.12.18 |
| [Django REST API] 6. Setup the Database (0) | 2021.12.18 |
댓글