The API needs to specify api version application/vnd.api+json;version=1
, also it needs secure x-app-id and x-app-secret. Is there a way to specify that in RESTAdapter in Ember?
After Trying request header
App.Adapter = DS.RESTAdapter.extend({
namespace: 'api',
beforeSend: function(xhr) {
xhr.setRequestHeader('x-my-custom-header', 'some value');
}
})
SOLUTION
App.Adapter = DS.RESTAdapter.extend({
bulkCommit: true,
namespace: 'api',
headers: {
'Accept': 'application/vnd.app+json;version=1',
'x-appid': '2375498237',
'x-secret': '238945298235236236236236375923'
},
ajax: function(url, type, hash) {
if (this.headers !== undefined) {
var headers = this.headers;
hash.beforeSend = function (xhr) {
Ember.keys(headers).forEach(function(key) {
xhr.setRequestHeader(key, headers[key]);
});
};
}
return this._super(url, type, hash);
}
});
App.Store = DS.Store.extend({ adapter: App.Adapter.create() });
App.Store = App.Store.create();
UPDATE #2
The solution mentioned above is no longer needed, as Ember now supports this behavior by default. You only need to supply headers
and it will automatically be added.
Check out the docs here http://emberjs.com/guides/models/connecting-to-an-http-server/#toc_custom-http-headers