Skip to content

Version 3.0 #1800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 203 commits into from
Nov 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
d8eb9e6
Docs whitespace fix.
tomchristie Aug 29, 2014
f62c874
Remove `filter_backend`.
tomchristie Aug 29, 2014
0f8fdf4
Remove `allow_empty`.
tomchristie Aug 29, 2014
b3bbf41
Remove `allow_empty`
tomchristie Aug 29, 2014
e5e6329
Remove `pk_url_field`, `slug_url_field`, `slug_field`.
tomchristie Aug 29, 2014
b8c8d10
Remove `page_size` argument.
tomchristie Aug 29, 2014
b3253b4
Remove `.model` usage in tests.
tomchristie Aug 29, 2014
72c0811
Minor tidy up.
tomchristie Aug 29, 2014
ce7b2cd
Remove deprecated generic views.
tomchristie Aug 29, 2014
f87d325
Remove `.link()` and `.action()` decorators.
tomchristie Aug 29, 2014
b552b62
`get_paginate_by` no longer takes optional `.queryset`
tomchristie Aug 29, 2014
371d30a
Remove unused imports.
tomchristie Aug 29, 2014
4ac4676
First pass
tomchristie Aug 29, 2014
ec096a1
Add relations and get tests running
tomchristie Sep 2, 2014
f285281
Getting tests passing
tomchristie Sep 2, 2014
c1036c1
More test passing
tomchristie Sep 3, 2014
d934824
Workin on
tomchristie Sep 5, 2014
21980b8
More test sorting
tomchristie Sep 8, 2014
b1c0767
Fleshing out serializer fields
tomchristie Sep 9, 2014
234369a
Tweaks
tomchristie Sep 10, 2014
01c8c0c
Added help_text argument to fields
tomchristie Sep 10, 2014
80ba047
Compat fixes
tomchristie Sep 10, 2014
de301f3
Merge master
tomchristie Sep 11, 2014
54ccf72
Improve memory address removal for serializer representations
tomchristie Sep 11, 2014
3318f75
Improve memory address removal for serializer representations
tomchristie Sep 11, 2014
ab40780
Tidy up lookup_class
tomchristie Sep 11, 2014
bf52d04
Nice manager representations on serializer classes
tomchristie Sep 11, 2014
19b8f77
Throttles now use Retry-After header and no longer support the custom…
tomchristie Sep 11, 2014
55650a7
no longer tightly coupled to private queryset API
tomchristie Sep 11, 2014
a751871
no longer tightly coupled to private queryset API
tomchristie Sep 11, 2014
040bfcc
NotImplemented stubs for Field, and DecimalField improvements
tomchristie Sep 11, 2014
1e53eb0
DecimalFields should still be quantized even without coerce_to_string
tomchristie Sep 11, 2014
adcb64a
MethodField -> SerializerMethodField
tomchristie Sep 12, 2014
0d354e8
to_internal_value() and to_representation()
tomchristie Sep 12, 2014
6db3356
NON_FIELD_ERRORS_KEY setting
tomchristie Sep 12, 2014
250755d
Clean up relational fields queryset usage
tomchristie Sep 12, 2014
5e39e15
UNICODE_JSON and COMPACT_JSON settings
tomchristie Sep 12, 2014
22af49b
Tidy up JSONEncoder
tomchristie Sep 12, 2014
79715f0
Coerce dates etc to ISO_8601 in seralizer, by default.
tomchristie Sep 12, 2014
f95e7fa
Updating docs
tomchristie Sep 12, 2014
b73a205
Tests for relational fields (not including many=True)
tomchristie Sep 12, 2014
0ac52e0
Use Resolver404 instead of base Exception
tomchristie Sep 12, 2014
1f75ffc
Access validation messages in a way thats compatible with 1.4, 1.5
tomchristie Sep 12, 2014
e6c88a4
Drop usage of validatiors.EMPTY_VALUES
tomchristie Sep 12, 2014
4fcecea
DecimalField documentation
tomchristie Sep 12, 2014
afb28a4
Dealing with reverse relationships
tomchristie Sep 12, 2014
40dc588
Drop label from serializer fields when not needed
tomchristie Sep 15, 2014
3cf7ed1
Fix erronous import
tomchristie Sep 15, 2014
c1e2a9c
Clean up field mapping tests
tomchristie Sep 15, 2014
0c15b97
Tests for reverse relationships
tomchristie Sep 15, 2014
d196608
Fix nested model serializer base class
tomchristie Sep 15, 2014
4ddc661
Tests for through relationships
tomchristie Sep 15, 2014
c0155fd
Update comments
tomchristie Sep 17, 2014
5b7e4af
get_base_field() refactor
tomchristie Sep 18, 2014
87734be
Configuration correctness tests on ModelSerializer
tomchristie Sep 18, 2014
3bc628e
Test for custom fields
tomchristie Sep 18, 2014
9fdb228
First pass on ManyRelation
tomchristie Sep 18, 2014
106362b
ModelSerializer.create() to handle many to many by default
tomchristie Sep 18, 2014
f900493
Added a model update integration test
tomchristie Sep 18, 2014
12ccb0f
Test tweaking
tomchristie Sep 19, 2014
6d73b59
Initial release notes
tomchristie Sep 19, 2014
88008c0
Merge branch 'master' into version-3.0
tomchristie Sep 19, 2014
c0150e6
Add BaseSerializer heading
tomchristie Sep 19, 2014
b361c54
Test rejigging
tomchristie Sep 19, 2014
cf72b9a
Moar tests
tomchristie Sep 19, 2014
af46fd6
Field tests and associated cleanup
tomchristie Sep 22, 2014
afb3f8a
Tests and tweaks for text fields
tomchristie Sep 22, 2014
c54f394
Ensure 'messages' in fields are respected in preference to default va…
tomchristie Sep 22, 2014
249253a
Fix compat issues
tomchristie Sep 22, 2014
4db23ca
Tweaks to DecimalField
tomchristie Sep 22, 2014
5586b65
Support format=None for date/time fields
tomchristie Sep 22, 2014
e5f0a97
More compat fixes
tomchristie Sep 22, 2014
b5454dd
Tests and tweaks for choice fields
tomchristie Sep 22, 2014
5a95baf
Tests & tweaks for ChoiceField
tomchristie Sep 22, 2014
5d80f7f
allow_blank, allow_null
tomchristie Sep 22, 2014
b187f53
Changed return status for CSRF failures to HTTP 403
dbrgn Jun 1, 2014
f22d0af
Tests for field choices
tomchristie Sep 23, 2014
0404f09
NullBooleanField
tomchristie Sep 23, 2014
aa84432
Merge pull request #1896 from dbrgn/csrf_response
tomchristie Sep 23, 2014
f4b1dcb
OPTIONS support
tomchristie Sep 24, 2014
630d472
Merge branch 'master' into version-3.0
tomchristie Sep 24, 2014
358445c
Drop redundant OPTIONS tests
tomchristie Sep 24, 2014
127c0bd
Custom deepcopy on Field classes
tomchristie Sep 24, 2014
fb1546e
Enforce field_name != source
tomchristie Sep 24, 2014
1420c76
Ensure proper sorting of 'choices' attribute on ChoiceField
tomchristie Sep 25, 2014
b22c960
Automatic field binding
tomchristie Sep 25, 2014
64632da
Clean up bind - no longer needs to be called multiple times in nested…
tomchristie Sep 25, 2014
b47ca15
Check for redundant on SerializerMethodField
tomchristie Sep 25, 2014
8ee92f8
Refuse to downcast from datetime to date or time
tomchristie Sep 25, 2014
3a5335f
Fix syntax error
tomchristie Sep 25, 2014
417fe1b
Partial support
tomchristie Sep 25, 2014
2859eaf
request.data attribute
tomchristie Sep 26, 2014
43e80c7
Release notes
tomchristie Sep 26, 2014
e8af73d
Release notes
tomchristie Sep 26, 2014
9031135
Release notes
tomchristie Sep 26, 2014
fde934d
Release notes
tomchristie Sep 26, 2014
8b8623c
Allow many, partial and context in BaseSerializer
tomchristie Sep 26, 2014
2e87de0
Added ListField
tomchristie Sep 26, 2014
0eb6a4d
Release notes
tomchristie Sep 26, 2014
24f7db2
Release notes
tomchristie Sep 26, 2014
33ccf40
Update version number
tomchristie Sep 26, 2014
ee79b45
Prepend some pre-release notes
tomchristie Sep 26, 2014
8be4496
Drop erronous print statements
tomchristie Sep 26, 2014
6090144
Simplify serialization slightly
tomchristie Sep 26, 2014
ac71d9a
Merge master
tomchristie Sep 26, 2014
dee3f78
FileField and ImageField
tomchristie Sep 26, 2014
ce04d59
Update release notes
tomchristie Sep 26, 2014
43fd5a8
Uniqueness validation
tomchristie Sep 29, 2014
9805a08
UniqueTogetherValidator
tomchristie Sep 29, 2014
d2d4129
.validate() on serializer fields
tomchristie Sep 29, 2014
4798df5
Update release notes
tomchristie Sep 29, 2014
657d1de
Latest release notes
tomchristie Sep 29, 2014
d1b2c8a
Absolute URLs for file fields
tomchristie Sep 29, 2014
83a5ea8
Update release notes
tomchristie Sep 29, 2014
da4900a
Update 3.0-announcement.md
tomchristie Sep 30, 2014
770d63f
Fixed documentation typo.
thedrow Oct 1, 2014
bb22229
Merge pull request #1911 from thedrow/patch-7
tomchristie Oct 1, 2014
3817717
Use six.text_type instead of str everywhere
tomchristie Oct 1, 2014
c630a12
Deal with lazy strings in serializer reprs
tomchristie Oct 1, 2014
c171fa2
First pass at HTML form rendering
tomchristie Oct 1, 2014
ffc6aa3
More forms support
tomchristie Oct 1, 2014
79e91df
The encoder now returns tuples instead of lists.
thedrow Oct 2, 2014
df7b6fc
First pass on incorperating the form rendering into the browsable API
tomchristie Oct 2, 2014
fec7c4b
Browsable API tweaks
tomchristie Oct 2, 2014
dfab9af
Minor: fix spelling and grammar, mostly in 3.0 announcement
craigds Oct 2, 2014
857a848
More spelling tweaks
craigds Oct 2, 2014
dd47d8a
Merge pull request #1921 from koordinates/fix-typos
tomchristie Oct 3, 2014
765b0b3
Revert accidental stupidity
tomchristie Oct 3, 2014
01c0857
Merge branch 'version-3.0' of https://github.com/tomchristie/django-r…
tomchristie Oct 3, 2014
e6c5ebd
Fix indentation
tomchristie Oct 3, 2014
3a3e2bf
Serializer.save() takes keyword arguments, not 'extras' argument
tomchristie Oct 3, 2014
6bfed6f
Enforce uniqueness validation for relational fields
tomchristie Oct 7, 2014
3fa4a18
Reintroduce save hooks
tomchristie Oct 7, 2014
093febb
Tests for relational fields
tomchristie Oct 8, 2014
6b09e5f
Tests for generic relationships
tomchristie Oct 8, 2014
af0f01c
Move generic relation tests
tomchristie Oct 8, 2014
0cbb57b
Tweak pre/post save hooks. Return instance in .update().
tomchristie Oct 8, 2014
28f3b31
.validate() returning validated data. transform_<field> hooks.
tomchristie Oct 8, 2014
14ae52a
More gradual deprecation
tomchristie Oct 8, 2014
4c015df
Tweaks
tomchristie Oct 8, 2014
5ead8dc
Support empty file fields
tomchristie Oct 8, 2014
f7d43f5
Limit blank string -> None to just be on relational fields
tomchristie Oct 8, 2014
87fdc73
Merge pull request #1920 from thedrow/topic/encoder-improvements
tomchristie Oct 9, 2014
a58cfe1
Update tutorial for 3.0
tomchristie Oct 9, 2014
5f4cc52
Tweaking
tomchristie Oct 9, 2014
6637b2f
Document the Metadata API
tomchristie Oct 9, 2014
babdc78
Typo
tomchristie Oct 9, 2014
5d247a6
First pass on nested serializers in HTML
tomchristie Oct 9, 2014
f83ed19
Checks and repr on BoundField
tomchristie Oct 9, 2014
a0e852a
Use BoundField .name on fields
tomchristie Oct 9, 2014
d9a199c
exceptions.ValidationFailed, not Django's ValidationError
tomchristie Oct 10, 2014
d8a8987
Tweaks
tomchristie Oct 10, 2014
b5a4216
Flake8
tomchristie Oct 10, 2014
826b5a8
Relations in 'read_only_fields' should not include a queryset kwarg
tomchristie Oct 10, 2014
81abf2b
Rename `preform_update` to `perform_update`
Oct 12, 2014
ad16b50
Merge pull request #1942 from rouge8/preform-to-perform
tomchristie Oct 12, 2014
f8f1012
Update 3.0-announcement.md
wolfe Oct 14, 2014
e272a36
Fix 'lookup_field' on ModelSerializer. Closes #1944.
tomchristie Oct 15, 2014
faa5bd9
Merge branch 'version-3.0' of https://github.com/tomchristie/django-r…
tomchristie Oct 15, 2014
e558f80
Drop template includes
tomchristie Oct 15, 2014
cc1c423
Reorganize to use template_pack in form rendering
tomchristie Oct 15, 2014
9ffa97d
Merge pull request #1956 from wolfe/patch-1
tomchristie Oct 15, 2014
36fbc76
Moar form styling
tomchristie Oct 15, 2014
22b27cb
Merge branch 'version-3.0' of https://github.com/tomchristie/django-r…
tomchristie Oct 15, 2014
e8ea365
Moar form styling
tomchristie Oct 15, 2014
b4f3379
Support fields that reference a simple callable
tomchristie Oct 15, 2014
4248a6c
Add a keys method to BindingDict
gulopine Oct 16, 2014
2648442
Merge pull request #1958 from gulopine/version-3.0
tomchristie Oct 16, 2014
d0f610b
Update release notes
tomchristie Oct 16, 2014
7b666e9
Stricter checking for failure cases.
tomchristie Oct 16, 2014
32fd82b
get_attribute method on fields
tomchristie Oct 16, 2014
3af5df1
Performance for PK fields
tomchristie Oct 16, 2014
5882a7a
Tweak
tomchristie Oct 16, 2014
05cbec9
Use serializers.ValidationError
tomchristie Oct 17, 2014
c5d1be8
.validate() can raise field errors or non-field errors
tomchristie Oct 22, 2014
ae53fdf
First pass at unique_for_date, unique_for_month, unique_for_year
tomchristie Oct 22, 2014
f9c0e6e
unique_for_month, unique_for_year
tomchristie Oct 22, 2014
702f477
Updated requirements
tomchristie Oct 24, 2014
9ebaabd
unique_for_date/unique_for_month/unique_for_year
tomchristie Oct 28, 2014
0dea509
Nested serializer tests
tomchristie Oct 30, 2014
cd40dcb
Ensure json.dumps(separators=...) works on both 2.x and 3.x
tomchristie Oct 30, 2014
2762205
Validator documentation and tweaks
tomchristie Oct 31, 2014
2547012
Fix up validators docs
tomchristie Oct 31, 2014
45b5f23
Update to bootstrap 3. Closes #1085
tomchristie Oct 31, 2014
159c3de
Merge master
tomchristie Oct 31, 2014
0e59c27
Merge branch 'master' into version-3.0
tomchristie Oct 31, 2014
3dfb6b0
Merge master
tomchristie Oct 31, 2014
bacf8cf
Guard against malicious string inputs for numbers. Closes #1903.
tomchristie Oct 31, 2014
11075d3
Merge branch 'master' into version-3.0
tomchristie Oct 31, 2014
207208f
Lazy loading of fields and validators. Closes #1963.
tomchristie Oct 31, 2014
6da3813
Merge master
tomchristie Oct 31, 2014
964b340
typo fix
andybak Nov 1, 2014
1ef4e6b
Merge pull request #2006 from andybak/patch-1
tomchristie Nov 1, 2014
56d054e
Proper escaping of URLs when replacing query parameter
tomchristie Nov 3, 2014
ddc1777
Merge branch 'master' into version-3.0
tomchristie Nov 3, 2014
37b0995
Merge branch 'version-3.0' of https://github.com/tomchristie/django-r…
tomchristie Nov 3, 2014
3784596
Merge master
tomchristie Nov 3, 2014
d27b8cc
PUT as create docs, and move mixin out to external gist
tomchristie Nov 3, 2014
9ce130d
Fixed some typos in 3.0 release notes
Nov 3, 2014
003c42b
Use invalid_data key for error message. Closes #2002.
tomchristie Nov 3, 2014
604728a
Merge pull request #2011 from fusionbox/announcement_typos
tomchristie Nov 3, 2014
2b53595
Py2/3 compat for validation test
tomchristie Nov 3, 2014
8861a7d
Merge branch 'version-3.0' of https://github.com/tomchristie/django-r…
tomchristie Nov 3, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ You can also use the excellent [`tox`][tox] testing tool to run the tests agains

It's a good idea to make pull requests early on. A pull request represents the start of a discussion, and doesn't necessarily need to be the final, finished submission.

It's also always best to make a new branch before starting work on a pull request. This means that you'll be able to later switch back to working on another seperate issue without interfering with an ongoing pull requests.
It's also always best to make a new branch before starting work on a pull request. This means that you'll be able to later switch back to working on another separate issue without interfering with an ongoing pull requests.

It's also useful to remember that if you have an outstanding pull request then pushing new commits to your GitHub repo will also automatically update the pull requests.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ There is a live example API for testing purposes, [available here][sandbox].
# Requirements

* Python (2.6.5+, 2.7, 3.2, 3.3, 3.4)
* Django (1.4.2+, 1.5, 1.6, 1.7)
* Django (1.4.11+, 1.5.5+, 1.6, 1.7)

# Installation

Expand Down
22 changes: 21 additions & 1 deletion docs/api-guide/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,27 @@ Corresponds to `django.db.models.fields.FloatField`.

## DecimalField

A decimal representation.
A decimal representation, represented in Python by a Decimal instance.

Has two required arguments:

- `max_digits` The maximum number of digits allowed in the number. Note that this number must be greater than or equal to decimal_places.

- `decimal_places` The number of decimal places to store with the number.

For example, to validate numbers up to 999 with a resolution of 2 decimal places, you would use:

serializers.DecimalField(max_digits=5, decimal_places=2)

And to validate numbers up to anything less than one billion with a resolution of 10 decimal places:

serializers.DecimalField(max_digits=19, decimal_places=10)

This field also takes an optional argument, `coerce_to_string`. If set to `True` the representation will be output as a string. If set to `False` the representation will be left as a `Decimal` instance and the final representation will be determined by the renderer.

If unset, this will default to the same value as the `COERCE_DECIMAL_TO_STRING` setting, which is `True` unless set otherwise.

**Signature:** `DecimalField(max_digits, decimal_places, coerce_to_string=None)`

Corresponds to `django.db.models.fields.DecimalField`.

Expand Down
20 changes: 16 additions & 4 deletions docs/api-guide/generic-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Typically when using the generic views, you'll override the view, and set severa

from django.contrib.auth.models import User
from myapp.serializers import UserSerializer
from rest_framework import generics
from rest_framework.permissions import IsAdminUser
from rest_framework import generics
from rest_framework.permissions import IsAdminUser

class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
Expand Down Expand Up @@ -212,8 +212,6 @@ Provides a `.list(request, *args, **kwargs)` method, that implements listing a q

If the queryset is populated, this returns a `200 OK` response, with a serialized representation of the queryset as the body of the response. The response data may optionally be paginated.

If the queryset is empty this returns a `200 OK` response, unless the `.allow_empty` attribute on the view is set to `False`, in which case it will return a `404 Not Found`.

## CreateModelMixin

Provides a `.create(request, *args, **kwargs)` method, that implements creating and saving a new model instance.
Expand Down Expand Up @@ -370,6 +368,20 @@ If you are using a mixin across multiple views, you can take this a step further

Using custom base classes is a good option if you have custom behavior that consistently needs to be repeated across a large number of views throughout your project.

---

# PUT as create

Prior to version 3.0 the REST framework mixins treated `PUT` as either an update or a create operation, depending on if the object already existed or not.

Allowing `PUT` as create operations is problematic, as it necessarily exposes information about the existence or non-existance of objects. It's also not obvious that transparently allowing re-creating of previously deleted instances is necessarily a better default behavior than simply returning `404` responses.

Both styles "`PUT` as 404" and "`PUT` as create" can be valid in different circumstances, but from version 3.0 onwards we now use 404 behavior as the default, due to it being simpler and more obvious.

If you need to generic PUT-as-create behavior you may want to include something like [this `AllowPUTAsCreateMixin` class](https://gist.github.com/tomchristie/a2ace4577eff2c603b1b) as a mixin to your views.

---

# Third party packages

The following third party packages provide additional generic view implementations.
Expand Down
103 changes: 103 additions & 0 deletions docs/api-guide/metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<a class="github" href="metadata.py"></a>

# Metadata

> [The `OPTIONS`] method allows a client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.
>
> &mdash; [RFC7231, Section 4.3.7.][cite]

REST framework includes a configurable mechanism for determining how your API should respond to `OPTIONS` requests. This allows you to return API schema or other resource information.

There are not currently any widely adopted conventions for exactly what style of response should be returned for HTTP `OPTIONS` requests, so we provide an ad-hoc style that returns some useful information.

Here's an example response that demonstrates the information that is returned by default.

HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json

{
"name": "To Do List",
"description": "List existing 'To Do' items, or create a new item.",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"note": {
"type": "string",
"required": false,
"read_only": false,
"label": "title",
"max_length": 100
}
}
}
}

## Setting the metadata scheme

You can set the metadata class globally using the `'DEFAULT_METADATA_CLASS'` settings key:

REST_FRAMEWORK = {
'DEFAULT_METADATA_CLASS': 'rest_framework.metadata.SimpleMetadata'
}

Or you can set the metadata class individually for a view:

class APIRoot(APIView):
metadata_class = APIRootMetadata

def get(self, request, format=None):
return Response({
...
})

The REST framework package only includes a single metadata class implementation, named `SimpleMetadata`. If you want to use an alternative style you'll need to implement a custom metadata class.

## Creating schema endpoints

If you have specific requirements for creating schema endpoints that are accessed with regular `GET` requests, you might consider re-using the metadata API for doing so.

For example, the following additional route could be used on a viewset to provide a linkable schema endpoint.

@list_route(methods=['GET'])
def schema(self, request):
meta = self.metadata_class()
data = meta.determine_metadata(request, self)
return Response(data)

There are a couple of reasons that you might choose to take this approach, including that `OPTIONS` responses [are not cacheable][no-options].

---

# Custom metadata classes

If you want to provide a custom metadata class you should override `BaseMetadata` and implement the `determine_metadata(self, request, view)` method.

Useful things that you might want to do could include returning schema information, using a format such as [JSON schema][json-schema], or returning debug information to admin users.

## Example

The following class could be used to limit the information that is returned to `OPTIONS` requests.

class MinimalMetadata(BaseMetadata):
"""
Don't include field and other information for `OPTIONS` requests.
Just return the name and description.
"""
def determine_metadata(self, request, view):
return {
'name': view.get_view_name(),
'description': view.get_view_description()
}

[cite]: http://tools.ietf.org/html/rfc7231#section-4.3.7
[no-options]: https://www.mnot.net/blog/2012/10/29/NO_OPTIONS
[json-schema]: http://json-schema.org/
29 changes: 5 additions & 24 deletions docs/api-guide/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,18 @@ If your API includes views that can serve both regular webpages and API response

Renders the request data into `JSON`, using utf-8 encoding.

Note that non-ascii characters will be rendered using JSON's `\uXXXX` character escape. For example:
Note that the default style is to include unicode characters, and render the response using a compact style with no unnecessary whitespace:

{"unicode black star": "\u2605"}
{"unicode black star":"★","value":999}

The client may additionally include an `'indent'` media type parameter, in which case the returned `JSON` will be indented. For example `Accept: application/json; indent=4`.

{
"unicode black star": "\u2605"
"unicode black star": "★",
"value": 999
}

**.media_type**: `application/json`

**.format**: `'.json'`

**.charset**: `None`

## UnicodeJSONRenderer

Renders the request data into `JSON`, using utf-8 encoding.

Note that non-ascii characters will not be character escaped. For example:

{"unicode black star": "★"}

The client may additionally include an `'indent'` media type parameter, in which case the returned `JSON` will be indented. For example `Accept: application/json; indent=4`.

{
"unicode black star": "★"
}

Both the `JSONRenderer` and `UnicodeJSONRenderer` styles conform to [RFC 4627][rfc4627], and are syntactically valid JSON.
The default JSON encoding style can be altered using the `UNICODE_JSON` and `COMPACT_JSON` settings keys.

**.media_type**: `application/json`

Expand Down
48 changes: 45 additions & 3 deletions docs/api-guide/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ A format string that should be used by default for rendering the output of `Date

May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.

Default: `None`
Default: `'iso-8601'`

#### DATETIME_INPUT_FORMATS

Expand All @@ -281,7 +281,7 @@ A format string that should be used by default for rendering the output of `Date

May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.

Default: `None`
Default: `'iso-8601'`

#### DATE_INPUT_FORMATS

Expand All @@ -297,7 +297,7 @@ A format string that should be used by default for rendering the output of `Time

May be any of `None`, `'iso-8601'` or a Python [strftime format][strftime] string.

Default: `None`
Default: `'iso-8601'`

#### TIME_INPUT_FORMATS

Expand All @@ -309,6 +309,46 @@ Default: `['iso-8601']`

---

## Encodings

#### UNICODE_JSON

When set to `True`, JSON responses will allow unicode characters in responses. For example:

{"unicode black star":"★"}

When set to `False`, JSON responses will escape non-ascii characters, like so:

{"unicode black star":"\u2605"}

Both styles conform to [RFC 4627][rfc4627], and are syntactically valid JSON. The unicode style is prefered as being more user-friendly when inspecting API responses.

Default: `True`

#### COMPACT_JSON

When set to `True`, JSON responses will return compact representations, with no spacing after `':'` and `','` characters. For example:

{"is_admin":false,"email":"jane@example"}

When set to `False`, JSON responses will return slightly more verbose representations, like so:

{"is_admin": false, "email": "jane@example"}

The default style is to return minified responses, in line with [Heroku's API design guidelines][heroku-minified-json].

Default: `True`

#### COERCE_DECIMAL_TO_STRING

When returning decimal objects in API representations that do not support a native decimal type, it is normally best to return the value as a string. This avoids the loss of precision that occurs with binary floating point implementations.

When set to `True`, the serializer `DecimalField` class will return strings instead of `Decimal` objects. When set to `False`, serializers will return `Decimal` objects, which the default JSON encoder will return as floats.

Default: `True`

---

## View names and descriptions

**The following settings are used to generate the view names and descriptions, as used in responses to `OPTIONS` requests, and as used in the browsable API.**
Expand Down Expand Up @@ -378,4 +418,6 @@ An integer of 0 or more, that may be used to specify the number of application p
Default: `None`

[cite]: http://www.python.org/dev/peps/pep-0020/
[rfc4627]: http://www.ietf.org/rfc/rfc4627.txt
[heroku-minified-json]: https://github.com/interagent/http-api-design#keep-json-minified-in-all-responses
[strftime]: http://docs.python.org/2/library/time.html#time.strftime
2 changes: 2 additions & 0 deletions docs/api-guide/throttling.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ To create a custom throttle, override `BaseThrottle` and implement `.allow_reque

Optionally you may also override the `.wait()` method. If implemented, `.wait()` should return a recommended number of seconds to wait before attempting the next request, or `None`. The `.wait()` method will only be called if `.allow_request()` has previously returned `False`.

If the `.wait()` method is implemented and the request is throttled, then a `Retry-After` header will be included in the response.

## Example

The following is an example of a rate throttle, that will randomly throttle 1 in every 10 requests.
Expand Down
Loading