I'm using Backbone.js with C# REST services, however we have separate endpoints for GETTING and POSTING data back to the server.
Using Backbone, how can we create our own unique save methods?
I'm using Backbone.js with C# REST services, however we have separate endpoints for GETTING and POSTING data back to the server.
Using Backbone, how can we create our own unique save methods?
You need override Backbone.sync()
.
You can do this globally for your application or specific to your model(s).
The best explanation and pattern I've seen comes from Addy Osmani's Developing Backbone.js Applications: http://addyosmani.github.io/backbone-fundamentals/#backbones-sync-api
The pattern is really nice because you define your persistence API elsewhere, and just assign the methods based on the request and method.
Also, here is really resourceful QA: How to override Backbone.sync?
Have a look at the Backbone.service
plugin: https://github.com/mkuklis/backbone.service
It allows your to include non-restful endpoints in your model.