Ads Top

When to Use GET vs POST

When you don't think about the basics of development day to day, you tend to forget the how and the whys and just get in a pattern of doing. Then when you think about they why, or are asked about the why, you may not have a "definition" at the ready.

Take for example the two common HTTP methods GET and POST when communicating between a client and a server. When should you favor one over the other?





Now that we know the basics of what differentiates GET and POST, we can now go over these rules for when (or when not) to use one versus the other.

Rule 1
Use GET for save actions (retrieving data) Use POST for unsafe actions (inserting or editing data)

Rule 2
Use POST when dealing with sensitive data

Rule 3
Use POST when dealing with long requests
The max URL length limit is 2048. This affects GET (point 4 on the GET graphic above)

Rule 4
Use GET in Ajax environments.
XMLHttpRequests implement POST as a 2 step process (sending headers first then data). Thus, GET requests are more responsive.

2 comments:

Powered by Blogger.