Reputation: 451
I am developing a SpringBoot Application. For a POST end-point, there is NO request body to be passed. My service is working fine. But its also working when I pass some values in the body of the request. How can I validate and return a BAD REQUEST if something is passed in the body of request which should ideally remain empty for this request?
*@RequestMapping(value = "/sample/customers", method = POST)
public Customer session() {
return customerService.getCustomer();
}*
Upvotes: 0
Views: 95
Reputation: 549
You should not use POST for data retrieval.
You'll need 2 methods. Here is an example code for the save:
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(value = "/sample/customers", method = POST)
public Customer save(@RequestBody CustomerRequestDto customerRequestDto) {
return customerService.save(customerRequestDto);
}
Upvotes: 0