0

I am creating a web Server using spring boot. Now In Response, I want to send my Status Code when some api hits the server.I want to create my own Status code . Like instead of Sending 401 , I want to send 421.

Response.status(421) Something like this.

Prakhar
  • 15
  • 3

1 Answers1

0

Is this what you're looking for?

@GetMapping("/test")
public ResponseEntity<String> someTest() {
   return ResponseEntity
      .status(421)
      .contentType(MediaType.TEXT_PLAIN)
      .body("go away world");
}

Testing...

$ curl -I http://localhost:8080/test
HTTP/1.1 421
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: SAMEORIGIN
Content-Type: text/plain
Content-Length: 11
Date: Tue, 03 Sep 2019 12:23:58 GMT
Andy Brown
  • 11,766
  • 2
  • 42
  • 61