-2

Why cannot we use GET instead using POST method in rest service,ignore what exactly POST does(creating new data/records).

user3274140
  • 123
  • 3
  • 13

1 Answers1

0

There could be different answers that your interviewer was looking for, two that I came up with:

  • This is a convention that you use POST to create, PUT to modify, GET to get and DELETE to remove. And we should follow conventions.

  • browsers support GET not POST, so if it's a service which is called by the browser - you can't use POST (it's not totally accurate, because the browser uses javascript which supports POST - but you get the gist of it).

That said, your application may not follow convention and use POST to get information and GET to create a new entity and etc. It's going against good practice but it's possible to do, so asking "why can't we use POST" is wrong because we can use it if that's what we want to do...

By the way, the other way around is not symmetric: GET is limited with the length of the URL so while POST may send a huge payload, GET might not be able to send the same amount of data!

Community
  • 1
  • 1
Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129