Search code examples
javascriptember.jsember-dataember-cli-mirage

Ember Mirage - Not able to capture the response


A newbie to ember, I am trying to simulate the API server using ember-cli-mirage. I am creating a request from account.js through store but the response is not something I expect.

## /app/routes/account.js

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default Route.extend({
  store: service(),

  model() {
    this.store.findAll('accounts').then(response => {
      console.log(response)
    });
    // return this.store.findAll('accounts');
  }
});



## /app/mirage/config.js

export default function () {
  this.get('/accounts', (schema) => {
    return {
      data: [
        {
          firstName: 'John'
        }
      ]
    };
  }, {timing: 2000});
}

This is the response I get, enter image description here

Is there anything missing?


Solution

  • You're logging response which is actually the return value of store.findAll, rather than the HTTP response from Mirage.

    store.findAll wraps up the HTTP request/response logic, and actually responds with an instance of an Ember Data model, or an array of models. In your case since you called findAll, the response is an array of Ember Data models.

    If you want to see the details of Mirage's response, check your console for something like Mirage: 200 OK for GET /accounts. You should be able to expand that to see the details of the request and response that Mirage handled.