Update resource using any params other than the id (PK)

What is the JSON API way to update a resource using any params other than the id (PK)?


instead of
PUT posts/:id // SQL: UPDATE posts WHERE id = 1; 

something like 
PUT posts?userId=1 // SQL: UPDATE posts WHERE userId = 1;

Bulk updates are not supported by the JSON:API specification itself. It could be supported using extensions. The official Atomic Operations extension supports updating multiple resources at once.

Updating a resource without identifying it by its type and id is not even supported by the Atomic Operations extension. Such a use case does not seem to fit well with the core assumptions of the JSON:API specification. Most noticeable that it is about fetching and mutating resources. Applying an operation to all resources identified using filter criteria seems to not fit well into that concept.

Having that said, an extension specifying such operations is possible. Such an extension would need to cover at least three aspects:

  1. How to identify the resources, which should be updated? Most likely some filter syntax is needed. Specifying a generic filter syntax is known to be a challenge as it is in most cases a trade-off between limiting flexibility for clients and database performance issues caused by applying filters, which the database schema is not optimized for. Beside that there are many smaller questions to answer like support for polymorphic collections.
  2. How to specify the changes, which should be applied to that resource? Can the client only specify new values for attributes and relationships? Can it provide some logic to calculate the new value (e.g. increment an integer)?
  3. How to inform the client of all resources, which have been changed? Should it return all affected resources as primary data? Would support for pagination of that collection be needed as the collection may be huge? Etc.

Personally I’m not sure if it’s worth it. There are only few use cases in which a client wants to apply an update without knowing all affected resources upfront.