0Pricing
Django Academy · 강의

APIView와 함수형 @api_view

두 가지 방식으로 엔드포인트를 만듭니다

APIView와 함수형 @api_view은(는) CoddyKit의 무료 Django Academy 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Django Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Django Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Two Ways to Build Endpoints

DRF lets you write endpoints as classes with APIView or as plain functions decorated with @api_view. Both speak the same JSON dialect.

The Class Style

APIView subclasses Django's View but gives you DRF's request parsing, content negotiation, and tidy response handling for free.

from rest_framework.views import APIView

Methods Map to Verbs

In an APIView you write a method per HTTP verb: get for reads, post for creates, and so on, keeping each action clearly separated.

class BookList(APIView):
    def get(self, request):
        ...
    def post(self, request):
        ...

Return a Response

Instead of HttpResponse, you return DRF's Response object, which renders to JSON or the browsable API based on the request.

from rest_framework.response import Response
return Response({'ok': True})

Read request.data

DRF parses the body for you, so you read posted JSON from request.data as a normal Python dict, no manual decoding needed.

title = request.data['title']

The Function Style

For simple endpoints the @api_view decorator turns an ordinary function into a DRF view, listing which HTTP methods it accepts.

from rest_framework.decorators import api_view

Declare Allowed Methods

You pass the verbs to the decorator. Any method not listed gets an automatic 405 Method Not Allowed, so you do not handle it yourself.

@api_view(['GET', 'POST'])
def books(request):
    ...

Same Response Object

Function views use the very same DRF Response, so you can mix class and function styles in one project without friction.

return Response(serializer.data)

Which Style to Pick

Reach for @api_view when an endpoint is small and one-off; choose APIView when you want reusable, organized methods on a class.

Set the Status

Both styles let you pass status= to Response so clients get the right HTTP code, like 201 when you create something new.

Response(data, status=201)

Same Power, Two Shapes

Whether class or function, you get DRF parsing, responses, and status handling, the difference is mostly structure and personal taste.

Quick Check

What does @api_view do to a plain function?

Recap: Two View Styles

You can build endpoints with class-based APIView or function-based @api_view, both returning a DRF Response. Pick the shape that fits. 🧩

자주 묻는 질문

“APIView와 함수형 @api_view” 강의는 무료인가요?

네 — “APIView와 함수형 @api_view” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Django Academy 강의 전체를 잠금 해제할 수 있습니다. Django Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“APIView와 함수형 @api_view”에서 뭘 배우나요?

두 가지 방식으로 엔드포인트를 만듭니다 브라우저에서 직접 실행하는 실습 코드로 Django Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Django Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Django Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“APIView와 함수형 @api_view” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Django Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Django Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. DRF 설치와 구성
  2. 시리얼라이저: 모델에서 JSON으로
  3. APIView와 함수형 @api_view
  4. 탐색 가능한 API와 상태 코드
← Django Academy(으)로 돌아가기