POST, PATCH, DELETE - single vs bulk operations


JSON API requires a single object to be passed to POST, PATCH and DELETE operations. However in the extensions to the api the bulk operations would use an array of objects. So the bulk operation would automatically include single object case for POST, PATCH and DELETE. It would be enough to pass an array with a single object to the corresponding bulk method to eliminate need for a separate method that would deal with single object. Do you plan on combining those two cases in the future? What would be your recommendation for implementation single method for POST, PATCH and DELETE while implementing corresponding bulk operations?




The way we have handled this in our framework is to first implement the base JSON API spec. We then implemented the JSON PATCH extension by accepting that format (signified by the appropriate headers) and translating it to the appropriate single-operation format. We then iterate and run it through an internal state machine to process it the same way we would have if it had come in as a separate request.

It is important to note that we do not internally fire off more web requests, we merely use the same mechanism to execute the functionality. For an example, you can see how we handle single operation POST requests vs, a JSON PATCH ‘add’ operation.