14

I would like to use ember-data in a project I am building, but the API I am working with does not follow REST conventions.

For example, all the HTTP requests are POST and the naming conventions of the endpoints are unique to the actions they perform. e.g. /api/thing/retrieve would require me to post a JSON object with some parameters, and would return a 'thing' to me.

Do I use the Restful adapter and reopen the class and redefine the various find functions?

OR

Do I have to make a new adapter?

OR

Should I just abandon ember-data and and use ajax in my models(or maybe even controllers)?

I'm not sure how I would handle any of those options. Any guidance would be appreciated.

user1168427
  • 1,003
  • 3
  • 10
  • 16

2 Answers2

1

The only information which I have seen on this subject has been an article by the Discourse folks linked below.

http://eviltrout.com/2013/03/23/ember-without-data.html

I personally have toyed around with the reopenClass method in the article, and would probably drop it into a mixin or something to that effect if I had a consistent but non-REST API which I was calling regularly.

nrion
  • 248
  • 1
  • 7
  • So if I understand this correctly, you say "don't create a customer adapter", rather, add your own ajax methods to a model. – tigrish Mar 28 '13 at 13:55
  • The method in the answer above is definitely much more robust and is something I'd experiment for anything complex. However, I've not dug into the ember-data/adapter docs at all to see what's involved in writing a custom adapter. For a couple of models, I still would probably just put the ajax calls in; more complex than that and the research and writing would be worth the time cost. – nrion Mar 28 '13 at 17:08
0

I would say that, if your API is consistent (reliable) then you should create/extend the DS.Adapter (not DS.RESTAdapter) to implement to your specification.

All the hooks are there, you will just end up defining it once which all models can use.

I would also read through the Basic Adapter code - (https://github.com/emberjs/data/blob/master/packages/ember-data/lib/adapters/basic_adapter.js) it might be a better staring point for you then DS.Adapter.

If your API is not reliable, then you are probably better off with just using the $.ajax() calls as necessary. But, in my opinion, that does not scale well.

A link worth reading when looking at Basic Adapter: http://emberjs.com/blog/2013/03/22/stabilizing-ember-data.html

One last note, building an ORM or even a something more simple then an ORM is not a trivial task, that for me, makes using ember-data worth the effort, and yes sometimes pain.

mspisars
  • 844
  • 8
  • 21
  • Do you have any examples of a non-REST action in a custom adapter (preferably one that is called on a model instance)? Reading over the basic adapter basically just shows the implementation for the existing REST actions. – tigrish Mar 28 '13 at 13:57
  • @tigrish the only thing that I have is http://emberjs.com/blog/2013/03/22/stabilizing-ember-data.html which talks about the Basic Adapter and gives an example of an implementation. – mspisars Mar 28 '13 at 16:29