0

I set up my ApplicationAdapter as such:

App.ApplicationAdapter = DS.RESTAdapter.extend({
    headers: {
        'X-Api-Key': 'ABCDEF'
    }
});

Now I need to be able to read the current headers property of Ember's instance of App.ApplicationAdapter, so I can add to it:

var headers = {}; /* HOW DO I GET THE CURRENT HEADERS? */
headers['X-My-New-Header'] = 'someValue';
App.ApplicationAdapter.reopen({ headers: headers; });

How can I read the current headers?

Kerrick
  • 7,420
  • 8
  • 40
  • 45

1 Answers1

2

I think that you can change by object reference:

App.httpHeaders = {
  'X-Api-Key': 'ABCDEF'
}

App.ApplicationAdapter = DS.RESTAdapter.extend({
  headers: App.httpHeaders
});

// in some action etc
App.httpHeaders['X-Api-Key'] // "ABCDEF"
App.httpHeaders['foo'] = "Bar"
// etc

Or the ugly way: Taking the adapter instance via container.

var headers = App.__container__.lookup('adapter:application').headers
headers['X-Api-Key'] // "ABCDEF"
headers['foo'] = "Bar"
// etc
Marcio Junior
  • 19,078
  • 4
  • 44
  • 47
  • I would highly recommend setting your headers when you extend from the RESTAdapter. – Marc Feb 06 '14 at 18:16