While reading difference between PUT
and POST
, I came across this answer which says:
An HTTP PUT is supposed to accept the body of the request, and then store that at the resource identified by the URI.
An HTTP POST is more general. It is supposed to initiate an action on the server. That action could be to store the request body at the resource identified by the URI, or it could be a different URI, or it could be a different action.
And now while going through this tutorial, I found this:
@RequestMapping(value = EmpRestURIConstants.DELETE_EMP, method = RequestMethod.PUT)
public @ResponseBody Employee deleteEmployee(@PathVariable("id") int empId) {
logger.info("Start deleteEmployee.");
Employee emp = empData.get(empId);
empData.remove(empId);
return emp;
}
I was thinking if I am using PUT
I should be using @RequestBody
. But this doesnt seem to be the case. And above method seem to use PUT
very much like GET
, right? Or I am missing anything here?
Q1. What are clear purpose of these methods, or at least when certain methods "cannot" be used?
Q2. Is it like, if I am using GET
, then I cannot use @RequestBody
, as GET
request doesnt contain any and I am left with using only @RequestParam
and @PathVariable
and PUT
and POST
can use all. And irrespective of methods all can return @ResponseBody
. If all these guessings are correct, is their any official documentation explaining all these restrictions, including for other methods too?