0

I want to return , 555 status code in response.

I have checked ResponseEntity class of spring framework.

I can see all constructors accept only particular codes from HttpStatus enum. This can be achieved by ,

return ResponseEntity.status(HttpStatus.CREATED).contentType(MediaType.TEXT_PLAIN).body("Custom string answer");

Is there any way to return status code like 555?

VedantK
  • 9,728
  • 7
  • 66
  • 71

2 Answers2

1

You can't do that using the Spring ResponseEntity.

But you can always get a hold of the underlying HttpServletResponse and do a response.setStatus(555).

As a side note, if your question was "is it OK to return non-standard HTTP codes in this scenario?", the answer would've probably been "no".

Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92
1

You can do it in Spring:

ResponseEntity.status(555).body("String or obj")
Dmitry
  • 557
  • 5
  • 12