title: Best way of sending REST responses in spring boot
body: <p>What is the best way to send rest responses in spring boot? Also how should i manage sending status codes to do it properly?</p>
  
  <p>Currently i do it using ResponseEntity but i doubt this is the most elegant way.</p>
  
  <p>Sample code:</p>
  
  <pre><code>@PostMapping()
  public ResponseEntity post(@Valid @RequestBody Item item, BindingResult bindingResult){
  
      if (bindingResult.hasErrors()){
          return new ResponseEntity&lt;&gt;(new ModelErrors(bindingResult), HttpStatus.BAD_REQUEST);
      }
  
      return new ResponseEntity&lt;&gt;(itemService.addItem(item), HttpStatus.CREATED);
  }
  </code></pre>
  
  <p>ModelErrors class extends a HashMap class and just fetches and wraps the BindingResult's error messages.</p>