Open Data (OData)
Breeze can consume any standard OData feed "as is" when you configure the client for OData.
Configure the client for your OData service
Breeze is not configured for OData services out of the box but it's easy to tell Breeze that you want to talk to an OData source. The first step is to configure your Breeze application's "data service adapter" which handles direct communication with remote data services.
The catch is that you have to pick the right adapter for your OData source. OData may be a "standard" but not all OData services are the same. They often diverge from the specifications in ways that can be painful for you.
We discuss the diversity of OData services (and the consequences) in a separate topic devoted to OData on the Server. Be sure to read it carefully.
Industry standard and WCF OData sources
Most industry standard OData services (including Microsoft's WCF OData) should work with the "standard" OData data service adapter shipped in Breeze core. Configure your application to talk to this source before executing any Breeze server call. You might add this to your application bootstrapping:
// "Standard" Web API OData source (e.g., WCF OData) breeze.config.initializeAdapterInstance('dataService', 'odata', true);
ASP.NET Web API OData
We highly recommend the Pluralsight course "Building ASP.NET Web API OData Services" by Brian Noyes. The module, "Consuming OData Services...", demonstrates consuming a Web API OData service with Breeze.
Web API OData does not comply with the OData specification for metadata and has other peculiarities that you should consider in your design. Please read about this in OData on the Server
Breeze core ships with two data service adapters, one "standard" and one for use with ASP.NET Web API OData. Pick one of these two configurations as appropriate.
// ASP.NET Web API OData breeze.config.initializeAdapterInstance('dataService', 'webApiOData', true);
This Breeze client can retrieve standard OData metadata, submit standard OData query requests, and interpret the results as Breeze entities using the OData HTTP URI protocol.
Both of the aforementioned Breeze OData adapters depend upon datajs to handle lower level communications with OData sources. Be sure to include that script before Breeze.js itself.
Setting the service address
You must specify an absolute path for your service address (AKA serviceName), e.g,
"http://localhost:1234/odata"</code> instead of just <code>"/odata". Relative paths work for queries but apparently not for
Adding headers and other configuration
The Breeze OData DataService adapters, "OData" and "webApiOData", rely on the DataJS
OData component to handle AJAX calls. If you need to add custom headers or otherwise manipulate the HTTP request, you'll need to configure the
OData.defaultHttpClient as described in the "Controlling AJAX calls" topic.
When you save entities, the entire change-set becomes a $batch request consisting of multiple nested HTTP requests for each entity. The DataService adapters build these requests for you. You can adjust the $batch details via each adapter's
Support for other OData sources
We will be adding more dataServiceadapters for other popular sources. Stay tuned.