Can I change link in POST request?


#1

I need to change my Post request link that view smth like this

POST http://somesrv.com/api/users

to

POST http://somesrv.com/api/user

without s in the end. Can i do this?


#2

You need to user serializer to alter the requests and adapter to communicate with server

This is one of my serializer

import DS from 'ember-data';
import Ember from 'ember';

export default DS.RESTSerializer.extend({
  modelNameFromPayloadKey: function (payloadKey) {
    //incoming data
    return this._super('settings/design/' + payloadKey);
  },
  payloadKeyFromModelName: function (modelName) {
    // out going data
    modelName = modelName.replace('settings/design/', '');
    modelName = Ember.String.dasherize(modelName);
    return modelName;
  }
});

This is my adapter

import Ember from 'ember';
import ApplicationAdapter from '../../../application/adapter';

export default ApplicationAdapter.extend({
  pathForType: function (modelName) {
    // this is for preflights urls
    modelName = modelName.replace('settings/design/', 'design/');
    var decamelized = Ember.String.decamelize(modelName);
    return Ember.String.pluralize(decamelized);
  }
});

You can see in my adapter i have replaced the settings/designs/ with design/ that is for url

and in my Payload, i dont want to see settings/designs so I have removed it before sending the data, and adding it back for incoming data in my serializers

You can add as many serializers and adapters as you like. I am using POD structure