Some helper classes and functions for Django REST Framework for building hypermedia APIs in the DocJSON document format.
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
Same as Django Rest Framework's reverse()
but wraps the returned URL in {'_type': 'link': 'url': '...'}
.
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.