Reputation: 2463
After writing tests for my REST API (built using Spring Boot), I realised that, even when the request body is not used (see below), calling the endpoint with a request body succeeds–effectively, Spring ignores the body.
This is not a huge issue, but I was wondering what philosophy I should approach this with:
@PatchMapping(value = "/products/{pid}/sell")
public TxDTO sell(@NotBlank @PathVariable("pid") String pid,
@NotNull @RequestParam Float price)
Upvotes: 0
Views: 348
Reputation: 9266
I think you shouldn't think too much into this. Technically, ignoring the unexpected body doesn't violate any software development principles. Even though this might be something that makes you feel uncomfortable personally in the context of your project, you might want to consider other scenarios where there's a filter or servlet sitting in front of your @RestController
doing some additional stuff you're not aware of.
The point is this is not a feature you should turn off globally nor it is worth spending time implementing custom code to turn it off locally for a single endpoint :).
Upvotes: 2