Any thoughts/tips/examples on using sails as the backend API for ember?
Particularly, what is the best why to make the default sails rest format confirm to what ember expects?
Is it maybe better to make ember accept sails format?
I use Sails version 0.10@rc-7 for a realtime Ember app. I started with this adapter and this serializer and āhackedā them together.
Iāve been thinking for a while now to make my versions open source so their quality can be improved a lot.
Thanks!
So you do it with no change to the sails blueprint API?
Iām very interested in this. Iām surprised that sails doesnāt have an ember-adapter (does it?)
I think sails could be an excellent backend, mostly because of its easy support for sockets.
It would have been really cool though if the integration were easier.
Yes, the blueprint api that Sails offers is untouched in my app.
You can find my version of the adapter here and my serializer here.
The serializer transforms the Sails payload to the expected Ember payload. This is the preferred way (imo) since your API might be used for other things too, editing your whole api makes no sense.
Please note that these versions are edited on the fly while developing my own app, so I wouldnāt recommend using it in production. But it should definitely help you start.
I have pluralize: false, maybe both work. No idea if Iām honest.
For example I have this route:
App.GameRoute = Ember.Route.extend({
model: function (params) {
return this.store.find('game', params.game_id);
}
});
```
It makes a request to `127.0.0.1:1337/api/game/1` when I go to `127.0.0.1:1337/#/game/1`.
Same for `Games` route
Makes a request to `127.0.0.1:1337/api/game/`, so singular, not plural.
These requests are made over sockets by default when using the `SailsSocketAdapter`.
Hi @ofridagan. There is an unfortunate bug currently with the Ember Sails Adapter where the SailsSocketAdapter uses singular model names in its routes and the the SailsRESTAdapter uses plural model names in its routes. There is a pr that fixes that issue where Iāve been waiting on some feedback but I can merge that now and push out a new release.
Iāve been using Ember Dataās built in JSONSerializer to work around Sailsās lack of a root-element in its response payload. This requires defining your relationships as āasyncā which have some annoying edge cases in Ember Data at the moment. As a result Iād defiantly suggest go down the path of using @m19ās serializer.
If I understand correctly the fix adds the option to use plural for SailsSocketAdapter. There is still no option to not use plural with SailsRESTAdapter, right?
The fix makes it so the SailsRESTAdapter uses singular route names by default (SailsSocketAdapter was already working this way). This is in line with the default sails.js behavior.
If you would like to use plural model names in your route you will need to extend the SailsRESTAdapter and set pluralize: true" in the blueprint config.
I am very interested in using Sails.js as the backend as well and will probably try it for one of the next projects. Good to see that there is some more interested. Even though I have seen the ember-sails-adapter my strategy would probably to create a blueprint to change it on the server-side (donāt like doing that kind of stuff on the client-side if I have control over the API).
Thatās interesting. I was also thinking about the best way to go.
I think I would also like to keep Ember as it is because it is more compatible with http://jsonapi.org/
Itās a shame jsonapi is not yet the standard.
Just starting to work with Sails 0.10 and it is really simple to override the default JSON response using blueprints.
Might push it to a repository so other people can save the grunt work.
@GlobeCoder Also curious about your Sails blueprints for Ember, since Iām more or less half way through writing/modifying my own blueprints and I also thought about releasing them open source. Maybe a good idea to do this together?