Sails.js and Ember.js integration - ember.js

Has anyone tried to use sails as ember's backend API?
How would you go about it?
Is there an example available?
Since Sails has a different format in its built-in blueprints, is it better to make sails rest json format confirm to what ember expects or the other way around?
Thanks!
Edit
So there are two approaches:
change the sails format, maybe with: CRUD blueprint overriding in sails.js
change what ember expects: http://discuss.emberjs.com/t/sails-js-as-the-backend/5233

There is a project called Sane Stack that uses a Sails blueprint to generate the appropriate setup for Ember and Sails, as well as provides a generator for creating resources in Ember and Sails at the same time.
QUICKSTART
npm install -g sails sane-cli
sane new project --docker creates project with sails-disk and Docker. For production databases see Options.
sane generate resource user name:string age:number to generate a new API on the backend and models on the frontend
sane up to start the sails server on localhost:1337 as well as the ember dev server on localhost:4200.
To work on your frontend-app you work as you would normally do with ember-cli on localhost:4200.
You are now good to go.
Note: If you use Docker, make sure you have fig installed. On Mac or Windows also boot2docker and for Linux see: https://docs.docker.com/installation/ubuntulinux/

I can't speak for the "change what Ember expects" option, but I can say that this is precisely what blueprint overrides in Sails were invented for. This would be a perfectly reasonable way to make your app Ember-compatible.
Also keep in mind that all of the CRUD blueprints use the res.ok() response to actually send data down to the client; if you like, you can just override that with your own api/responses/ok.js, perhaps using req.url to determine the resource that was being requested, and use that to wrap your JSON object in the manner that Ember expects.

I just put up a few blueprint overrides that can be used as a starting point for using Sails as an Ember Data backend: https://github.com/mphasize/sails-ember-blueprints
Please let me know if you find a bug or have some suggestions for improvements!

Haven't used ember in a few months, but the default blueprints responses are not compatible with ember-data.
Ember seems to be trying to conform to the jsonapi spec.
Sails default blueprint responses do not.
That being said, it would be pretty easy to roll your own responses with sails.

Related

How to use django as backend for cordova?

Not a web developer, but currently playing with cordova and would like to use django to use python to implement backend functionality. As I (vaguely) understand it, cordova manages frontend stuff and django is mostly for backend stuff. So is it possible to use django as a backend for a cordova project (eg. directly use preexisting django templates in a cordova app)? If so, how? Is there some kind of special communicationn that I'd need to code myself?
(My uneducated guess would be to initialize the django project inside the cordova www folder, but this seems wrong). And if this is a totally wrong way to think about this problem, let me know.
You could use Django as your backend and implement a REST like API (urls that accept and return JSON data) in it. There are useful tools/libraries for that, for example django-rest-framework.
Then you would call those endpoints (URLs) from your frontend, which can be written in cordova or any other JS frontend frameworks.
As you already pointed out, I suggest keeping frontend and backend code in separate folders.

Why does Ember.js require a server?

I've downloaded Ember.js ver 1.13.13 for a test drive.
With other js frameworks, I am able to run from a file system. Does Ember require a server? I could not run directly from a file system. I did find some old tutorials that allows this. Is this a new thing?
You are using Ember-CLI which requires running ember serve in order to view your ember app. Ember-CLI uses conventions so that it knows where to locate the files that compose your ember app. As Ember-CLI locates your files, it knows how to combine them in a manner that ultimately results in the single JavaScript file that is executed in your browser. In theory you could use the globals style of development-which is the style reflected in the 'old tutorials' that you reference-and run the app directly without using any sort of "server." But, I don't recommend that. Learning Ember-CLI is useful as it is the preferred method of development moving forward. And, in my opinion, gives you a number of features that allow you to more quickly prototype apps. You can read more about that in the link I provided to the Ember-CLI website.

Ember.js consuming REST Services

I have been working on a web app using .NET web forms. Now I'm trying to move to a Web API and a client side application. I'm trying to use Ember.js right now. I'm starting to get confused with Ember 2.0, Ember-Data and stuff.
My problem right now is that I'm trying to consume some of the REST services in order to show a list of things in my Ember app. Is it mandatory for me to use Ember-Data? If not, how can I consume the services to create, read, update and delete items (I mean, am I able to use only ajax or something)?
The Web API was built in order to be usable for many technologies. I need to build an specific URL for each request (even a simple GET has some mandatory parameters). That's why ember-data is not working well for me, at least not what I have learnt about it. Because this.store.find won't allow me to build the URL I need.
Greetings.
Is it mandatory for me to use Ember-Data?
No, it's not. You can use other libraries such as Ember RESTless, or write your own.
You can even use simple jQuery AJAX calls whenever you need to fire a request to your API, however, you'll loose many benefits of Ember Data, such as lazy, asynchronous loading of models when they are needed.
That's why ember-data is not working well for me, at least not what I
have learnt about it. Because this.store.find won't allow me to build
the URL I need.
You can override buildURL method of adapter you're using(for example RESTAdapter), source code on GitHub could be helpful if you would like to do that, and you can find everything you need to create your own behavior for buildURL method in Ember API documentation.

What should I use instead of DS.FixtureAdapter

You gotta love ember.js team... I'm getting this depreciation message saying that: "DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master". Guys maintaining that addon advise that we should use a library similar to Pretender. Has anybody done that? Is there a tutorial showing how to integrate this lib so that everything would work as before?
If you are using ember-cli it comes with an http-mock out of the box letting you quickly setup fixtures in a more realistic test scenario. For instance, for a Conversation model you would mock it by running the following prompt on your command line.
ember g http-mock conversations
This will scaffold an endpoint located at server/mocks/conversations.js that your real adapters will use to get data when you run ember serve. You can modify this file to your liking to return whatever fixtures / mock data you want for the various CRUD operations you need.
Server mocks:
Ember CLI's http-mock
Clientside mocks:
Pretender.js
jQuery mockjax
Ember CLI Mirage, basically sugar around Pretender
Clientside mocking has some advantages like portability, making it easy to use in a CI environment, but server mocks let you take advantage of express middleware.
Note: I maintain Mirage. You can watch a screencast & overview here.
I like to use http-mocks with ember-cli. In addition I like to use raw JSON files as the payloads for each endpoint here is an example setup https://github.com/pixelhandler/ember-fixturific/pull/1/files

What is needed server-side to use ember-data?

I'm trying to get started with ember; after reading all the documentation, now i'm trying to move the example todo app to a server;
In the example the app is configured for using the LS Adapter for local data;
if i want to use data from the server, what i need to handle the ember-data get request?
I'm a beginner in this; what i mean is: is needed some kind of servlet to deal with ember-data? Where the data should be stored on the server?
I spent hours on google but i still confused about this; can you provide some input to drive me in the right direction?
You can use any web-server technology stack you like with Ember Data. Ember data is just the frontend 'module'/'component' used to send requests to that server depending on actions invoked by your ember app, so it can keep everything in sync.
You simply build a RESTful API for your Ember App to consume and make sure the JSON you return is in the format ember data expects.
You could look at ember-rails, a good starting point for rails-based ember apps with ember data.