1
1
===============================
2
- Ember and Django Rest Framework
2
+ Ember Data and Django Rest Framework
3
3
===============================
4
4
5
- EmberJS is extremely opinionated on how JSON REST requests and responses
6
- should look. Going against the grain can lead to frustrated Javascript
7
- developers.
5
+ The default Ember Data REST Adapter conventions differ from the default
6
+ Django Rest Framework JSON request and response format. Instead of adding
7
+ a Django specific adapter to Ember Data we use this adapter in Django to
8
+ output and accept JSON in the format the Ember Data REST Adapter expects.
8
9
9
10
By default, Django REST Framework will produce a response like::
10
11
11
12
{
12
- "id": 1,
13
- "username": "john",
14
- "full_name": "John Coltrane"
13
+ "count": 20,
14
+ "next": "http://example.com/api/1.0/identities/?page=2",
15
+ "previous": null,
16
+ "results": [
17
+ {
18
+ "id": 1,
19
+ "username": "john",
20
+ "full_name": "John Coltrane"
21
+ },
22
+ {
23
+ ...
24
+ }
25
+ ]
15
26
}
16
27
17
28
18
- However, if this is an ``identity `` model in EmberJS, Ember expects a
19
- response to look like the following::
29
+ However, for an ``identity `` model in EmberJS, the Ember Data REST Adapter
30
+ expects a response to look like the following::
20
31
21
32
{
22
- "identity": {
23
- "id": 1,
24
- "username": "john",
25
- "full_name": "John Coltrane"
33
+ "identity": [
34
+ {
35
+ "id": 1,
36
+ "username": "john",
37
+ "full_name": "John Coltrane"
38
+ },
39
+ {
40
+ ...
41
+ }
42
+ ],
43
+ "meta": {
44
+ "count": 20,
45
+ "next": "http://example.com/api/1.0/identities/?page=2",
46
+ "previous": null
26
47
}
27
48
}
28
49
@@ -61,6 +82,7 @@ override ``settings.REST_FRAMEWORK``::
61
82
62
83
63
84
REST_FRAMEWORK = {
85
+ 'PAGINATE_BY': 10,
64
86
'DEFAULT_PARSER_CLASSES': (
65
87
'rest_framework_ember.parsers.EmberJSONParser',
66
88
'rest_framework.parsers.FormParser',
@@ -74,6 +96,10 @@ override ``settings.REST_FRAMEWORK``::
74
96
}
75
97
76
98
99
+ If PAGINATE_BY is included the renderer will return a ``meta `` object with
100
+ record count and the next and previous links.
101
+
102
+
77
103
resource_name property
78
104
^^^^^^^^^^^^^^^^^^^^^^
79
105
0 commit comments