return only http status from the controller

hey guys. i want to ask for some help. i have a controller and i want it to return only http status and no body. can i do it this way?
@PostMapping(value = "/createPaymentConfirmation", produces = "application/json")
public ResponseEntity createPaymentConfirmation(@RequestBody @Valid PaymentDTO paymentConfirmationRequest) {
paymentService.createPaymentpaymentConfirmation(paymentConfirmationRequest);
ResponseEntity response = ResponseEntity.ok().build();
return response;
}
@PostMapping(value = "/createPaymentConfirmation", produces = "application/json")
public ResponseEntity createPaymentConfirmation(@RequestBody @Valid PaymentDTO paymentConfirmationRequest) {
paymentService.createPaymentpaymentConfirmation(paymentConfirmationRequest);
ResponseEntity response = ResponseEntity.ok().build();
return response;
}
it works, but i was wondering maybe smth can be done better? thx in advance
10 Replies
JavaBot
JavaBot5mo ago
This post has been reserved for your question.
Hey @bambyzas! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
tjoener
tjoener5mo ago
Just return void By default it will be a 200, unless authentication is wrong (4xx) or there's an exception (5xx)
0x150
0x1505mo ago
yeah thats the officially endorsed way
bambyzas
bambyzasOP5mo ago
i was told i can return ResponseEntity<Void> too or put @ResponseStatus(HttpStatus.NO_CONTENT) and make my controller method return void
0x150
0x1505mo ago
if you just want to return 200 or 204, then just return void and do nothing
bambyzas
bambyzasOP5mo ago
actually i need to return 204 No Content
0x150
0x1505mo ago
yeah thats what i meant i forgot the code
bambyzas
bambyzasOP5mo ago
ok
tjoener
tjoener5mo ago
This If you have a restcontroller, no need to put the produces in there either
JavaBot
JavaBot5mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server