I’m using the Play framework to build a web app which integrates with Salesforce via their REST API. In order to send an upsert command to their interface, it seems as if I must use the PATCH method instead of a POST method request. Is it possible to use Play’s WSRequest object and change the method type to PATCH instead of POST? If not, how can I use a request object and send a PATCH request instead?
For learning purposes, what is the PATCH method and why does Salesforce enforce use of it instead of a POST method?
I’m not sure about what is available in Play, but from the REST API documentation, here is a workaround if your library doesn’t support PATCH:
For example, to update an Account, this will work with an actual POST request:
As for the reasoning behind using PATCH, it is because PATCH is for partial updates to a resource. That is, you only have to send the fields you are updating. If you were required to send all the fields for a record in updates, PUT would probably be a better choice. POST is generally only for new inserts. Here is an explanation with examples:
http://jasonsirota.com/rest-partial-updates-use-post-put-or-patch