Reputation: 417
It's possible return a Mono<Object>
with statusCode 204
(NO_CONTENT)?
I need that, for example postman show something like this:
Upvotes: 3
Views: 11862
Reputation: 934
I'd suggest to use ResponseEntity , like this:
@RequestMapping(value = "/elb", method = RequestMethod.GET)
public ResponseEntity elbHealthCheck() {
return HealthStatus.HEALTHY.equals(healthService.getHealthStatus())
? ResponseEntity.ok().build()
: ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
Off course in your case, you just need to replace that HttpStatus code. Cheers!
Upvotes: 0
Reputation: 3698
It's not compatible return a Mono<Object>
with a http status 204. If you want a 204 you should return Mono<Void>
like this sample using routerFunctions:
public Mono<ServerResponse> checkWithout(final ServerRequest request) {
return noContent()
.build();
}
Upvotes: 1
Reputation: 21978
I recommend using ServerResponse
.
public Mono<ServerResponse> create(MyEntity entity) {
return just(save(entity))
.map(created(fromCurrentRequestUri()
.pathSegment("{id}")
.build()
.expand(entity.getId())
.toUri()).build());
}
Upvotes: 1
Reputation: 147
Use Mono<ResponseEntity<Object>>
instead of Mono<Object>
.
Response entity can be used to provide the proper response codes
For this case
return Mono.just(ResponseEntity.status(HttpStatus.NO_CONTENT).build());
Upvotes: 4
Reputation: 743
If using a Controller, this should do (replace path, method, etc as needed):
@GetMapping(value = "/no-content")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public Mono<Object> noContentMethod()
{
// ... processing here ...
return Mono.empty();
}
Upvotes: 4