Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Latest commit

 

History

History
executable file
·
36 lines (19 loc) · 1.3 KB

README.md

File metadata and controls

executable file
·
36 lines (19 loc) · 1.3 KB

DocJSON tools for Django REST Framework

Some helper classes and functions for Django REST Framework for building hypermedia APIs in the DocJSON document format.

Fields

DocJSONIdentityField

Subclass of HyperlinkedIdentityField that wraps the hyperlink in {'_type': 'link': 'url': '...'}:

from rest_framework_docjson.fields import DocJSONIdentityField

class ArticleSerializer(serializers.ModelSerializer):
    permalink = DocJSONIdentityField(view_name='article-detail')

class Meta:
    model = Article

Functions

reverse

Same as Django Rest Framework's reverse() but wraps the returned URL in {'_type': 'link': 'url': '...'}.

Renderers

DocJSONRenderer and UnicodeDocJSONRenderer

Adds to top level element {"_type": "document} to the serialized data before rendering. Also uses the view's get_view_name() and get_view_description() to populate the "meta": "title" and "meta": "description".

media type: 'vnd.document+json' format: 'docjson'

In accordance with the IANA assignment here.