Skip to content

Instantly share code, notes, and snippets.

@not-only-code
Last active December 18, 2015 21:49
Show Gist options
  • Save not-only-code/5850243 to your computer and use it in GitHub Desktop.
Save not-only-code/5850243 to your computer and use it in GitHub Desktop.
Backbone custom REST API urls
###
This test use Apiari.io REST sketch
###
class MyModel extends Backbone.Model
rootUrl: 'http://backbonecustomrest.apiary.io'
customUrls:
'read': '/my-path/1/get'
'create': '/my-path/1/create'
'update': '/my-path/1/update'
'delete': '/my-path/1/delete'
'custom-action' :'/my-path/1/custom-action'
sync: (method, model, options = {}) ->
method = method.toLowercase()
options.url = @rootUrl + @customUrls[method] + '/' + @get 'id'
if method is 'custom-action'
options.type = 'PATCH'
Backbone.sync(method, model, options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment