Retrieve a JSON from SAILS

Hi everybody, Here is my situation, I am using Sane Stack a CLI that works with Eember.js and Sails.js, I am creating a web application that interacts with the JIRA REST Api, here is a scheme to illustrate what I am trying to explain :

As the shown in the scheme above, the architecture of my web application is as follows, my Sails backend communicate with external API and retrieve data from it (e.g. Jira API) and I want my Ember client to get this data from Sails.

Indeed, I can get my JSON from the external API Sails side, in my browser I can display the retrieved JSON with this URL: In the Ember side, I tried to get this JSON in my project-view component:

import Ember from 'ember';
export default Ember.Component.extend({

        console.log("here we go !");
        return Ember.$.getJSON('');

But it returns nothing (Checked with the Ember Inspector), Am I doing it wrong ? can someone help me please ?

It is hard to say, but my guesses;

  • your ember models are not set up correctly
  • the JSON you retrieve is not formatted correctly (By correctly I mean not the way Ember Data expects it)

Pls post both of them.

1 Like

It looks like you are trying to load data in a component, but this is normally done in the route:

// app/router.js {

// app/routes/projects.js
export default Ember.Route.extend({
  model: function() {
    return Ember.$.getJSON('');

This will expose the model data in the template as model and you can pass that into your component {{display-projects projects=model}}.

You can read more about loading model data via the route in the Routing Guides.

1 Like

Thank you for the reply, so I don’t need to create a model “projects” that matches with the JSON attributes, right ?

I tried you suggestion but it dosen’t seem to work : “Error while processing route: projects” It occur once I try to diplay my Projects

Here is the JSON structure :

        "expand": "description,lead,url,projectKeys",
        "self": "",
        "id": "112366",
        "key": "CTA",
        "name": "CustApp",
        "avatarUrls": {
            "48x48": "",
            "24x24": "",
            "16x16": "",
            "32x32": ""

Using SANE stack Sails knows how Ember is expecting Data so he send the correct format.

and here is my model :

import DS from 'ember-data';

export default DS.Model.extend({
  expand: DS.attr('string'),
  self: DS.attr('string'),
  id: DS.attr('number'),
  key: DS.attr('string'),
  name: DS.attr('string'),
  avatars: DS.attr('string')

I don’t have a lot of experience with SANE stack but I do think that it uses Ember Data by default, and therefore it might be useful to set up a project model with the relevant attributes. See the Model Guides.

Then you could use'project') in place of getJSON.

Maybe @mgenev can give you a few pointers.