Setting up a Django API to use with Ember.js

We’re starting a brand new Django application here and are beginning write the API that Ember will access. A coworker decided to use Tastypie which appears to have issues with Ember. I wonder what others out there might be using

If you are using django and want a community driven REST framework that leverages the good of django be sure to checkout the latest django-rest-framework.

https://github.com/tomchristie/django-rest-framework

If you don’t need hypermedia support and prefer the vanilla (out of the box) REST api you could also checkout the full blown ember-data adapter that I wrote (currently works w/ RC1 if that matters to you)

I’ve had great luck w/ this adapter so far as long as you don’t mind the “limitations” of ember-data (ie- single transaction across your application).

Here is a sample I threw out on github (to show the adapter in action). It shows one to many/ m2m and one to one relationships + basic searching (with helper from django-filter)

https://github.com/toranb/complex-ember-data-example

About your Tastypie experience -what issues are you having w/ the adapter and your API ? ie- are you using embedded objects mixed or need some special behavior that your average REST Adapter for ember won’t offer out of the box?

Hi there,

We were using a vanilla REST API, powered by TastyPie, with the appropriate REST adapter.

There’s a demo app running at http://tastypie-ember-playground.herokuapp.com/.

I had quite a few difficulties getting this to work, the serialization expected by Ember was pretty different to the one generated by TastyPie, even with the REST adapter I struggled to get this to work. For example, to conform to the required format I had to tamper with the response from TastyPie, there were other issues as well, which were mostly addressed through configuration of my TastyPie resources.

Currently, I have been unable to get Ember-Data and TastyPie to play nice when saving records, and at this stage am considering abandoning TastyPie in favour of the Django REST Framework you mention above.

Cheers, Steve

Interesting to hear your frustrations with tastypie. Have you created an issue on the adapters github account to address the serialization issue in particular?

I faced the usual issues when I wrote the django rest framework adapter I use today but it wasn’t much work to be honest.

The top 3 issues I face w/ my adapter today are

  1. hypermedia is really a separate adapter waiting to be written (very different url structure)
  2. embedded objects are not yet supported
  3. transaction support when your REST api doesn’t respect that boundary (this is a non trivial issue I’m sure)

Just switched to the Django REST Framework and your Ember adapter, works perfectly. Nice job :slight_smile:

If your team is more comfortable with Tastypie, as we are, you can use the ember-data-tastypie-adapter: https://github.com/escalant3/ember-data-tastypie-adapter The adapter is currently being used by several members of the community

It provides interaction between Ember and Tastypie with no configuration. The adapter manages all the incompatibilities between the two JSON models.

You can see how easy is to set up in this dummy demo project https://github.com/escalant3/django-ember-example. It shows how to read records, and also how to create, update and delete objects.

We’ve been using the Tastypie adapter and it’s worked well for our purposes so far, the main drawback I’ve ran into is more a limitation of Tastypie in that it doesn’t support any form of sideloading currently.

There were some issues with embedded records before ember-data rev 11 but things seem to be working quite smoothly now.

The latest tastypie release has a very good framework for defining potentially complex permissions/authorization requirements which was a big win for our app.

Many thanks to escalant3 for maintaining the adapter.

1 Like

Thanks for the headsup @escalant3, we’re already moving forward with the Django Rest adapter and it seems to be working well for us so far.