Search code examples
spring-bootmicroservices

Different response structures for different "Success/2xx" response codes - Spring boot


Does microservice artchitecture/ rest api standards allow for different structures for different response codes like, say, for 200 and 207 ?

If yes, how can I implement the same in my spring boot restful application ?


Solution

  • The answer is yes, for example think about response code 200 vs. response code 404: with the first one a valid object will be returned, but for the second one - some error object should be returned. Completely different structures. About implementation, of course there are many ways, I'd recommend to take a look on ResponseEntity.