title: Registering a user using POST - how to correctly use ResponseEntity?
body: <p>I'm building REST API (not public, just for my own site's backend) and I have a Controller for registering new User: </p>
  
  <pre><code>  // CREATE A USER
  @PostMapping("/register")
  public ResponseEntity&lt;?&gt; createUser(
          @RequestBody User user
  ) {
      if (userService.userExists(user)) {
          return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("User with that username already exists.");
      }
      return ResponseEntity.ok(userService.saveUser(user));
  }
  </code></pre>
  
  <p>I don't like that String in my ResponseEntity when username is already taken - what is the correct way to handle those things? I know I should be returning JSONs from all of my controllers but I don't know how to implement that in that method. </p>
  
  <p>Also is returning in JSON only a username fine in this controller:</p>
  
  <pre><code>// DELETE YOUR ACCOUNT - deletes logged in user
  @DeleteMapping("/delete")
  public ResponseEntity&lt;?&gt; deleteUser(Principal principal) {
      userService.deleteUser(principal);
      return ResponseEntity.ok(principal.getName());
  }
  </code></pre>
  
  <p>I'm still very confused about what to return in REST Controllers - does everything have to be just JSONs (I know that I can use XML too (and some others) but chose JSONs) + status codes? Is that going to be easy to use when I try to build front-end for that webapp?</p>