I can achieve whatever a get/put/delete request achieves using a post request (by writing whatever the logic is inside the method). Then what is the point of having different methods.
There must definitely be a better reason other than just the semantics that this classification of methods was created in the first place. List down any scenarios in which my idea of implementing any method in post does not work.
Give me a good reason why I should not do the following.
Thanks in advance.
@PostMapping("/add")
public ResponseEntity<?> add(@RequestBody Something something) {
try {
Something result = someService.add(something);
return ResponseEntity.ok(result);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e);
}
}
@PostMapping("/getAll")
public ResponseEntity<?> getAll() {
try {
List<Something> result = someService.getAll();
return ResponseEntity.ok(result);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e);
}
}
Abhiram Danala is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.