Hi Rick,
So my devops guy continues to tell my engineers about the "right" way to do things. He suggested using PATCH instead of POST for the api. When I tell Websurge to use PATCH the request body disappears in the UI.
PATCH
POST
It's still there under the hood. I can switch back and forth and the body stays intact. Is this expected behavior?
Generally REST APIs use POST
and PUT
for inserts and updates if anything. PATCH
although more semantically correct is rarely used - in fact I never see that in API definitions for anything but binary updates.
That said WebSurge should support a body for PATCH - that's a bug.
And I want to remind you that REST is not a standard. It's a recommendation, and very few APIs follow the full recommendations. It means nothing other than making it easier for consumers of the API to more easily deduce what APIs do without looking at the documentation. I doubt anybody will be in doubt what an endpoint does if it uses POST instead of PUT or PATCH. Especially if the name of the endpoint is MarkItemAsPaid
😄.
The idea is the same - you're pushing data to the API. In 99% of the cases that endpoint will handle both inserts and updates, idempotent or not. Very few APIs need to make a distinction between these things and even most developers even understand what idempotent means much less spell it (me!), ha ha.
The way I approach it is: If I need to specifically handle insert and updates separately then yes I will use separate POST and PUT operations. In just about all other cases I would use POST. PATCH would never even cross my mind for usage although in the case of that specific API that updates one specific sub-value it's appropriate.
Another point: PATCH is not a common HTTP verb and often not directly supported by browser clients or servers. IIS by default supports only GET, POST, PUT, OPTION and HEAD. Other verbs have to be explicitly enabled (or are often enabled by the hosting tool platform like ASP.NET). CORS on the server has to specifically enable PATCH and so on.
Not saying it shouldn't be used, it's just not a common use case.
+++ Rick ---
Thanks, Rick. I appreciate the explanation.
Fixed the missing Patch content area and also added a separate icon.