Wrapping API views

REST framework provides two wrappers you can use to write API views.

  • The @api_view decorator for working with function based views.
  • The APIView class for working with class-based views.These wrappers provide a few bits of functionality such as making sure you receive Request instances in your view, and adding context to Response objects so that content negotiation can be performed.

The wrappers also provide behaviour such as returning 405 Method Not Allowed responses when appropriate, and handling any ParseError exception that occurs when accessing request.data with malformed input.