Sometimes you want to update multiple resources e.g. via REST sending a PUT /todos or DELETE /todos. Supporting this is fairly easy, the question is what method signatures to use. Currently I see two options.
Option 1: *Many service methods
We could add updateMany, patchMany and removeMany (and possibly createMany although it would just be passing an array to create).
var myService = {
find: function(params, callback) {},
get: function(id, params, callback) {},
create: function(data, params, callback) {},
update: function(id, data, params, callback) {},
updateMany: function(data, params, callback) {},
patch: function(id, data, params, callback) {},
patchMany: function(data, params, callback) {},
remove: function(id, params, callback) {},
removeMany: function(params, callback) {},
setup: function(app) {}
}
- + Backwards compatible
- - Cluttered service interface
Option 2: null values for id
The other option is to pass a null value as an id when operating on multiple resources.
app.use('/todos', {
remove: function(id, params, callback) {
if(id === null) {
}
}
}
- + Keeps service interface the same
- - Could break backwards compatibility in some cases (although you would most likely just return a
notFound error)
Sometimes you want to update multiple resources e.g. via REST sending a
PUT /todosorDELETE /todos. Supporting this is fairly easy, the question is what method signatures to use. Currently I see two options.Option 1:
*Manyservice methodsWe could add
updateMany,patchManyandremoveMany(and possiblycreateManyalthough it would just be passing an array tocreate).Option 2:
nullvalues foridThe other option is to pass a
nullvalue as an id when operating on multiple resources.notFounderror)