Basic difference between GET and POST-
GET request -
GET is usually used when you want to request some data from the server.
It has request header which contains URL of the requested resource and the request body is empty.
You can pass some parameters as query string in the GET request, but they appear in the URL.
Check below example:
...form?name="Name"&address="Address"
which means there exists a resource named form on the server and you are passing parameters name and address with values Name and Address.
POST request-
POST is used when you want to make some changes to the data on the server like posting new data, updating data, uploading files etc.
It has request header but unlike GET here the data is passed in the request body hence the data is hidden from the user.
Use POST over GET in below cases:
- Passing large amount of data to server : You might not want to pass large amount of data in the URL e.g. uploading files, URL would be very large hence use POST in such cases.
- Hide data from user : Since data is passed in request body, it will be hidden from the user. Even if the user bookmarks the URL it will not be visible to the user.