New Posts New Posts RSS Feed: Setting headers with request
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Setting headers with request

 Post Reply Post Reply
Author
sujesharukil View Drop Down
Newbie
Newbie
Avatar

Joined: 01-Nov-2012
Location: Pittsburgh
Posts: 5
Post Options Post Options   Quote sujesharukil Quote  Post ReplyReply Direct Link To This Post Topic: Setting headers with request
    Posted: 15-Nov-2012 at 8:30pm
This works. Thank you. Keep em updates coming!
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2012 at 10:34am
As of Breeze 0.70.1 we now support for the ability to completely customize or replace any ajax communication between the breeze client and the web service on the server.

The Breeze documentation on our Ajax support is still in progress, but hopefully the following will get you started.

To control the headers on every ajax request that breeze makes you can execute the following code when your app first starts up.

     var ajaxImpl = breeze.core.config.getAdapterInstance("ajax");
     ajaxImpl.defaultSettings = {
           headers: {
               // any CORS or other headers that you want to specify.
               "X-Test-Header": "foo2"
           },
    };
  
Alternatively, you can intercept the individual ajax calls and add your headers selectively based on the request.

     var ajaxImpl = breeze.core.config.getAdapterInstance("ajax");
     ajaxImpl.defaultSettings = {
           beforeSend: function(jqXHR, settings) {
                  // examine the jqXHR or settings and customize the headers accordingly.
                  jqXHR.setRequestHeader("X-Test-Before-Send-Header", "foo2");
           }
     };
Back to Top
sujesharukil View Drop Down
Newbie
Newbie
Avatar

Joined: 01-Nov-2012
Location: Pittsburgh
Posts: 5
Post Options Post Options   Quote sujesharukil Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2012 at 9:42pm
I can wait for the next release. I am still evaluating breeze. Although I see Breeze.js as a powerful way to manage data and models on the client side, I still feel there are a few things missing before it can be included in an enterprise level library. Granted it is in Beta and it can do a lot and I know I will continue to watch this project and some day be in a position to actually make it our preferred library for the enterprise.

The decision finally came down to Complex type support. I know Breeze.js does not support complex types and it is in your roadmap and when it does, I Will be back again.

Keep the great work going. I will be using Breeze for almost anything that I build now. thank you.

-Suj
Back to Top
jtraband View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 19-Sep-2012
Posts: 55
Post Options Post Options   Quote jtraband Quote  Post ReplyReply Direct Link To This Post Posted: 03-Nov-2012 at 12:52am
Great question!, and an oversight on our part.  We will be adding support for custom ajax headers in the next release, (or very soon thereafter).  I can give you a fix that involves hacking the source as a temporary fix if you need something sooner. 
Back to Top
sujesharukil View Drop Down
Newbie
Newbie
Avatar

Joined: 01-Nov-2012
Location: Pittsburgh
Posts: 5
Post Options Post Options   Quote sujesharukil Quote  Post ReplyReply Direct Link To This Post Posted: 02-Nov-2012 at 7:04pm
Another question. How do I set headers before letting breeze make a request?

Example: my service expects a certain key to be part of the request in a header name 'x-service-key'. Till now, I was using jquery ajax and amplify, so pretty easy to set up the header. Since I don't have any control over the request that breeze is making, how do I pass extra stuff like headers?

Thanks,
Suj
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down