<commit_before># REST Framework Siren

[![build-status-image]][travis]
[![pypi-version]][pypi]

**Siren hypermedia support for Django REST Framework**


## Overview

Siren hypermedia support extracted as a third party package directly from the official Django REST Framework implementation. It's based on the Siren specification located [here][siren].

## Requirements

* Python (2.7, 3.3, 3.4)
* Django (1.6, 1.7, 1.8)
* Django REST Framework (2.4+, 3.0+)

## Installation

Install using `pip`...

```bash
$ pip install djangorestframework-siren
```

## Example

```python
REST_FRAMEWORK = {
    # Optional - will simply set the media type to application/vnd.siren+json
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_siren.renderers.SirenRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
        ...
    ),
    
    # Also optional - will allow responses with a application/vnd.siren+json media type
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_siren.parsers.SirenParser',
        ...
    ),
    
    # Required - does the transformation into siren formatting
    'DEFAULT_PAGINATION_CLASS': 'rest_framework_siren.pagination.SirenPagination',
}
```

You must then use the serializers defined in the `rest_framework_siren.serizlizers` module.  
There is currently only support for the `ModelSerizlizer` and `HyperlinkedModelSerializer` types.

For example, if this is your current `serializers.py` file:
```python
from rest_framework import serializers

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')
```

Simply swap out the serializers import to use `rest_framework_siren` instead of `rest_framework`:
```python
# Use rest_framework_siren instead
from rest_framework_siren import serializers

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')
```


You can also set the renderer, parser, and paginator used for an individual view, or viewset, using the APIView class based views.

```python
from rest_framework import routers, viewsets
from rest_framework_siren import serializers  # NOTE - using rest_framework_siren.serializers
from rest_framework_siren.parsers import SirenParser
from rest_framework_siren.renderers import SirenRenderer
from rest_framework_siren.pagination import SirenPagination

# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')


# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    parser_classes = (SirenParser,)
    renderer_classes = (SirenRenderer,)
    pagination_class = SirenPagination
```




### Sample output

```json
{
  "class": "auth.user",
  "properties": {
    "email": "<EMAIL>",
    "is_staff": true,
    "username": "clarkperkins"
  },
  "links": [
    {"rel": ["self"], "href": "http://127.0.0.1:8000/users/1/"}
  ]
}
```

## Documentation & Support

Full documentation for the project is available at [http://clarkperkins.github.io/django-rest-framework-siren][docs].

You may also want to follow the [author][clarkperkins] on Twitter.


[build-status-image]: https://secure.travis-ci.org/clarkperkins/django-rest-framework-siren.svg?branch=master
[travis]: http://travis-ci.org/clarkperkins/django-rest-framework-siren?branch=master
[pypi-version]: https://img.shields.io/pypi/v/djangorestframework-siren.svg
[pypi]: https://pypi.python.org/pypi/djangorestframework-siren
[docs]: http://clarkperkins.github.io/django-rest-framework-siren
[clarkperkins]: https://twitter.com/rclarkperkins
[siren]: https://github.com/kevinswiber/siren<commit_msg>Fixed a couple of typos<commit_after># REST Framework Siren

[![build-status-image]][travis]
[![pypi-version]][pypi]

**Siren hypermedia support for Django REST Framework**


## Overview

Siren hypermedia support extracted as a third party package directly from the official Django REST Framework implementation. It's based on the Siren specification located [here][siren].

*Note:* As of the 0.1.0 release, `django-rest-framework-siren` does not support adding actions as specified by siren.

## Requirements

* Python (2.7, 3.3, 3.4)
* Django (1.6, 1.7, 1.8)
* Django REST Framework (2.4+, 3.0+)

## Installation

Install using `pip`...

```bash
$ pip install djangorestframework-siren
```

## Example

```python
REST_FRAMEWORK = {
    # Optional - will simply set the media type to application/vnd.siren+json
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_siren.renderers.SirenRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
        ...
    ),
    
    # Also optional - will allow responses with a application/vnd.siren+json media type
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_siren.parsers.SirenParser',
        ...
    ),
    
    # Required - does the transformation into siren formatting
    'DEFAULT_PAGINATION_CLASS': 'rest_framework_siren.pagination.SirenPagination',
}
```

You must then use the serializers defined in the `rest_framework_siren.serializers` module.  
There is currently only support for the `ModelSerizlizer` and `HyperlinkedModelSerializer` types.

For example, if this is your current `serializers.py` file:
```python
from rest_framework import serializers

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')
```

Simply swap out the serializers import to use `rest_framework_siren` instead of `rest_framework`:
```python
# Use rest_framework_siren instead
from rest_framework_siren import serializers

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')
```


You can also set the renderer, parser, and paginator used for an individual view, or viewset, using the APIView class based views.

```python
from rest_framework import routers, viewsets
from rest_framework_siren import serializers  # NOTE - using rest_framework_siren.serializers
from rest_framework_siren.parsers import SirenParser
from rest_framework_siren.renderers import SirenRenderer
from rest_framework_siren.pagination import SirenPagination

# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')


# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    parser_classes = (SirenParser,)
    renderer_classes = (SirenRenderer,)
    pagination_class = SirenPagination
```




### Sample output

```json
{
  "class": "auth.user",
  "properties": {
    "email": "<EMAIL>",
    "is_staff": true,
    "username": "clarkperkins"
  },
  "links": [
    {"rel": ["self"], "href": "http://1192.168.3.11:8000/users/1/"}
  ]
}
```

## Documentation & Support

Full documentation for the project is available at [http://clarkperkins.github.io/django-rest-framework-siren][docs].

You may also want to follow the [author][clarkperkins] on Twitter.


[build-status-image]: https://secure.travis-ci.org/clarkperkins/django-rest-framework-siren.svg?branch=master
[travis]: http://travis-ci.org/clarkperkins/django-rest-framework-siren?branch=master
[pypi-version]: https://img.shields.io/pypi/v/djangorestframework-siren.svg
[pypi]: https://pypi.python.org/pypi/djangorestframework-siren
[docs]: http://clarkperkins.github.io/django-rest-framework-siren
[clarkperkins]: https://twitter.com/rclarkperkins
[siren]: https://github.com/kevinswiber/siren
{'fraction_non_alphanumeric': 0.11563169164882227, 'fraction_numerical': 0.0076835873535709785, 'mean_word_length': 4.445816186556927, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1385921', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2422, 'n_words': 633}