Performance: @PostMapping for POST requests
This affects server response time and client perceived loading speed when handling POST requests.
@PostMapping("/submit") public CompletableFuture<ResponseEntity<String>> submitData(@RequestBody Data data) { return CompletableFuture.supplyAsync(() -> { processData(data); // async processing return ResponseEntity.ok("Success"); }); }
@PostMapping("/submit") public ResponseEntity<String> submitData(@RequestBody Data data) { // heavy synchronous processing processData(data); // long blocking operation return ResponseEntity.ok("Success"); }
| Pattern | Server Thread Usage | Response Delay | Client Impact | Verdict |
|---|---|---|---|---|
| Synchronous blocking in @PostMapping | High (blocks thread) | High (long delay) | Slow page load (LCP affected) | [X] Bad |
| Asynchronous processing in @PostMapping | Low (non-blocking) | Low (fast response) | Faster page load (better LCP) | [OK] Good |
@PostMapping annotation in Spring Boot?/greet?
@PostMapping("/greet")
public String greet(@RequestBody String name) {
return "Hi, " + name + "!";
}/register that accepts a JSON object with fields username and email, maps it to a Java record UserData(String username, String email), and returns a confirmation message. Which method signature correctly implements this?Pass the test and this pattern moves unknown