0
votes

I am pushing my data in a controller to the ember store like this:

    this.get('store').pushPayload({
        "user": [
            {
                "id":2,
                "name":this.get('name'),
                "passwort":this.get('admin')
            }
        ]
      });

This works temporally fine but after a reload on a route which uses findAll to get all users from mirage the new user is deleted out of the store. So is there any possibility to hold the new user into the ember store or to push the new object into the mirage database? I´ve tried to send a post-request on my own like this:

$.ajax({
  cache:false,
  type: 'POST',
  url: "/api/test",
  data: JSON.stringify(myData),
  contentType: "application/json",
  success:  function(data) {            
  //
    }
  });

My config.js part:

this.post('/test', function(schema, request) {
    console.log('foo');
  });

The foo comes up but how can I access my data? I have tried

this.post('/test', function(schema, request) {
    console.log('foo');
    console.log(request.data.user.name);
  });

this does not work because user is undefined.

1
have you tried /api/test in both url and config ?feiiiiii
oh no, this was my first fault. Thank you. Now the foo comes up in the console but i am stuck with the request param. How i can access the params there? I had edit my question + configurationspanx36

1 Answers

1
votes

Add namespace points to /api in app/mirage/config.js

this.namespace = '/api';

this.post('/test', function(schema, request) {
    console.log('You can have look at this request object. this will contains whateever you sent in request ',request);
    var params = JSON.parse(request.requestBody);
    console.log('params :',params);
  });

You can inspect params object to get the required params. for more information refer mirage docs