GET is used to retrieve data, POST is used to save, PUT is used to update existing data edit is common example of it, PATCH is lighter version of PUT , it is used to update just a specific information instead of updating all data on server DELETE is used to remove records.
In CRUD operations
C stands for create : POST
R stands for read : GET
U stands for update : PUT/PATCH
D stands for delete : DELETE
🎯𝐒𝐚𝐟𝐞/𝐔𝐧𝐬𝐚𝐟𝐞 𝐌𝐞𝐭𝐡𝐨𝐝𝐬
We can classify these methods in two ways safe methods and unsafe methods.
A method is known as safe method if it doesn't change the resource representation.
GET is a safe method and PUT/POST/PATCH/DELETE are not methods.
🎯𝐈𝐝𝐞𝐦𝐩𝐨𝐭𝐚𝐧𝐜𝐲
If we can call a method multiple times and doesn't effect our data, we can consider that method idempotent otherwise non idempotent.
GET/PUT/DELETE methods are idempotent and POST/PATCH are non idempotent.
Let's say you have added someone as friend, suppose facebook used a post request to save them as your friend. What if we send that request 10 times then it would be weird when you see a same person 10 times in your friends list.
Suppose you were updating a name of a facebook profile name even if you update a it n times it will set it same so no problem, request update n time is problem obviously but for idempotent POV no problem.
You were going to delete a record against a specific Id so record would be deleted first time then after that even if you make n requests no harm.
✉️Join 400+ Software Engineers to receive an actionable tip weekly in your inbox through my Newsletter.(lnkd.in/d69Va5CM)
✉️If you like my tweets, please join 400+ Software Engineers to receive an actionable tip weekly in your inbox through my Newsletter.(lnkd.in/d69Va5CM)
✅Use an overload of the String.Equals method to test whether two strings are equal
✅Use the String.Compare and String.CompareTo methods to sort strings, not to check for equality.
✅Use overloads that explicitly specify the string comparison rules for string operations. Typically, this involves calling a method overload that has a parameter of type StringComparison.