Skip to content

update, remove and patch many #144

Description

@daffl

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions