@PutMapping("/createUser") public String createUser(@RequestBody User user) { User thisValue = repository.findByUsername(user.getUsername()); if thisValue != null { sendResponseHeaders(400, -1); // wont work return "account exist"; } sendResponseHeaders(200, -1); // wont work return "reached here"; } com.sun.httpserver that I used before has a sendResponseheaders method and I cant find that on springboot. Is there anyway to accomplish this. Basically what I want it. If I send a json request body with a username that exist then a 400 response error should occur