Passing the QueryString in the headers of a REST call


#1

I would like to pass the queryString of the current rest call as a parameter in my headers.

Here is an example of code:

App.AppSessionAdapter.reopen({
    namespace: 'api',
    host: function () {
        return 'https://something/';
    }.property(),
    headers:
    {
        'AUTH': 'I need The QueryString to this REST Call. eg: UserID="12134"&Date="10/15/16"'
    }
});

Thanks for your help!


Why are my headers always giving an “Adapter operation failed” error?
#2

Since you require looking at the data you are sending on your request, you might want to look into extending the RESTAdapter and overriding the ajax method.

In there, use options.data to extend the Adapter’s headers, eg.

untested code

ajax: function(url, type, options) {
  var data = options.data || {};
  var headers = this.get('headers') || {};
  Ember.merge(headers, data);
  return this._super.apply(this, arguments);
}

#3

Thanks @neojp. That did it!


#4

Great! I didn’t even test it :slight_smile: