Inside a Backbone model, we have the url and urlRoot attributes:
url: function(){
return '/jobs'
},
urlRoot: function () {
return '/jobs'
},
however I want to add params or query params to the url, depending on what type of request it is GET, POST, PUT, DELETE, etc.
So I want to do something like this:
url: function(type, opts){ //type and opts arguments are not available in Backbone, I just made them up for this example
var url = '/jobs';
switch (type) {
case 'GET':
break;
case 'POST':
break;
case 'PUT':
url = url + '?optimisticDelete=' + opts.optimisticDelete;
break;
case 'DELETE':
url = url + '?upsert=' + opts.upsert;
break;
default:
throw new Error('no match');
}
return url;
},
is there a good way to accomplish something like this?