Search code examples
javascriptodatabreeze

Breeze.js - re-target save to custom endpoint


I communicate with OData services by using Breeze.js and wanna be able to get and save data. So there are two endpoints which should be used to get and save resources:

1. https://domain.com/smth/getdata
2. https://domain.com/smth/postdata

I created a manager which purpose is to get data, and send them back to server if needed:

var smthManager = new EntityManager(http://domain.com/smth/getdata);

After changing entities in smthManager I have to save them (by using endpoind 2). Investigating documentation I have found the next statement:

you can re-target a "save" to a custom server endpoint such as an arbitrarily named action method on a separate

So here is the code to "re-target a save":

var so = new SaveOptions({ resourceName: "postdata" }); // also tried with resourceName: 'http://domain.com/smth/postdata'
myEntityManager.SaveChanges(null, so );

But after all these manipulations what can I see that request was sent to https://domain.com/smth/getdata/$batch


Solution

  • Breeze with a WebApi or WebApi2 service supports multiple server endpoints. Breeze with an OData service does not because the OData spec itself only supports a single $batch save for a service.

    See http://www.odata.org/documentation/odata-v2-documentation/batch-processing/

    Note that any Breeze WebApi or WebApi2 service is a superset of what can be provided directly from an OData service and is in general just as easy to expose your model from ( as long as you have a .NET server).