0

I'm trying to call API controller which validates request's header (X-Session-id). How to configure oDataProvider to pass variable to request header?

var context = new JayData.SomeEntities({
            name: 'oData',
            oDataServiceHost: 'https://mydomain/RestService',
            headers: { 'X-SessionId': 'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5' }//How to put value here
        });
AndreyDG
  • 25
  • 4

1 Answers1

2

There are two ways: 1. if you initialize your context with $data.service, then you can add a third parameter with custom headers:

$data.service('url2yourService', function (factory) {
}, { httpHeaders: { 'X-SessionId': 'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5' } });

see: http://jaystack.com/blog/what-is-the-difference-between-data.service-and-data.initservice

or use prepareRequest

context.prepareRequest = function(cfg){
  cfg[0].headers['X-SessionId'] = 'f05d1c1e-b1b9-5a2d-2f44-da811bd50bd5';
};
Gabor Dolla
  • 2,680
  • 4
  • 14
  • 13