Skip to content

Commit

Permalink
Create 17.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nayong2021 committed Aug 12, 2023
1 parent fb13565 commit ff3ca5d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions 17.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 17. Building REST APIs With Django REST Framework

DRF가 성공할 수 있었던 이유
- DRF는 객체 지향 설계에 의존하며 쉽게 확장되도록 설계되었다.
- DRF는 Django의 CBV에서 바로 빌드되므로 CBV를 이해하면 DRF의 디자인을 Django의 확장처럼 느낄 수 있다.
- django.views.generic.View에 가까운 기본적인 APIView에서부터 고도로 추상화된 generic API view들과 viewsets까지 다양한 view들이 제공된다.
- serializer가 매우 강력하지만 사용하지 않거나 대체될 수도 있다.
- 인증과 권한부여를 다루는 강력하고 확장가능한 방법을 제공한다.
- FBV를 API를 위해 꼭 사용하고 싶다면 그러한 방법도 사용 가능하다.

## 17.1 Fundamentals of Basic REST API Design

|용도|HTTP Method|대응 SQL|
|--|--|--|
|자원 생성|POST|INSERT|
|기존 자원 읽기|GET|SELECT|
|기존 자원 업데이트|PUT|UPDATE|
|기존 자원 수정|PATCH|UPDATE|
|기존 자원 삭제|DELETE|DELETE|
|GET과 동일한 Header를 body없이 반환|HEAD||
|요청하는 URL에서 지원하는 HTTP Method 반환|OPTIONS||
|요청을 그대로 반환|TRACE||

참고사항:
- Read-Only API를 개발한다면 GET만 구현
- Read-Write API를 개발한다면 GET,POST,PUT 그리고 DELETE를 구현
- 모든 작업을 GET, POST에 대응시키는 것은 사용자 입장에서 좋지않은 패턴
- 정의상, GET, PUT, DELETE는 idempotent. POST와 PATCH는 그렇지 않다.
- PATCH는 보통 구현되지 않는 편이지만, PUT을 구현했다면 같이 구현하는게 좋다.
- DRF 역시 이러한 방법을 중심으로 설계되어있다.

## 17.2 Illustrating Design Concepts With a Simple API

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- [Chapter 10. Best Practices for Class-Based Views](10.md)

### Week 4 (08/16/2023) - [Charles Na](https://github.com/nayong2021)
- Chapter 17. Building REST APIs With Django REST Framework
- [Chapter 17. Building REST APIs With Django REST Framework](17.md)
- Chapter 22. Dealing With the User Model

### Week 5 (08/23/2023) - [Chavo Kim](https://github.com/chavokim)
Expand Down

0 comments on commit ff3ca5d

Please sign in to comment.