Skip to content

Supporting Data Formats Using Mixin's

cootetom edited this page Jun 12, 2011 · 1 revision

Mixin's are used with the APIView class to provide each data format that the API supports. This package comes with a simple JSONMixin already implemented.

A mixin does two jobs for the APIView.

  1. It looks for data in the request that it knows how to parse and if found parses that data into request.DATA ready for the API view method to use.
  2. It looks for the requested data format to receive back from an API call that it supports and if found parses any data returned from an API view method into a string as the response content.

The APIView can be extended to support new data formats by creating your own mixin's and adding them to the APIView inheritance list. The best way to see how to create a mixin is to look at the existing JSONMixin at ClassBasedGenericAPI.mixins.JSONMixin. They can be as straight forward or as complex as you need them for your API.

Clone this wiki locally