Method Safety and Idempotency

1. HTTP Methods Introduction
2. Method safety with examples
3. Method Idempotency with examples
🧵⏬

#csharp #dotnet #dotnetcore Image
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)

#csharp #dotnet #dotnetcore

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Muhammad Waseem

Muhammad Waseem Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mwaseemzakir

Feb 27
💡 Do and Don't for string in C#

1. Always use
2. Don't use 🔁

✉️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)

#csharp #dotnet #dotnetcore
✅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.
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(