xxxxxxxxxx
POST ===> always for creating a resource ( does not matter if it was duplicated )
PUT ===> for checking if resource exists then update, else create new resource
PATCH ===> always for updating a resource
xxxxxxxxxx
POST - Create NEW record
PUT - If the record exists, update else, create a new record
PATCH - update
GET - read
DELETE - delete
xxxxxxxxxx
PUT vs PATCH
PATCH is used to update an existing entity with new information.
You can’t patch an entity that doesn’t exist.
PUT is used to set an entity’s information completely. PUTting is
similar to POSTing, except that it will overwrite the entity
if already exists or create it otherwise.
xxxxxxxxxx
"put":
If I want to update my first name, then I send a put request:
{ "first": "Yus", "last": "Blah" }
But here is a problem with using put request: When I want to send put request
I have to send all two parameters that is first and last (whereas I only need
to update first) so it is mandatory to send them all again with put request.
"patch":
patch request, on the other hand, says: only specify the data which you need
to update and it won't be affecting or changing other data.
So no need to send all values again. Do I only need to change first name?
Well, It only suffices to specify first in patch request.
xxxxxxxxxx
POST is always for creating a resource
( does not matter if it was duplicated )
PUT is for checking if resource exists then update,
else create new resource.
PATCH is always for updating a resource.
GET is to read a record.
DELETE is to delete a record.