Challenge - 5 Problems
ResponseEntity Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the HTTP status code returned by this Spring Boot controller method?
Consider this Spring Boot controller method using ResponseEntity:
What HTTP status code will the client receive?
public ResponseEntitygreet() { return ResponseEntity.status(201).body("Created greeting"); }
What HTTP status code will the client receive?
Spring Boot
public ResponseEntity<String> greet() {
return ResponseEntity.status(201).body("Created greeting");
}Attempts:
2 left
💡 Hint
Look at the status method used in ResponseEntity.
✗ Incorrect
The method explicitly sets the status to 201, which means 'Created'. So the client receives HTTP 201.
❓ state_output
intermediate2:00remaining
What is the response body content returned here?
Given this Spring Boot controller method:
What will be the exact content in the HTTP response body?
public ResponseEntitygetMessage() { return ResponseEntity.ok("Hello World"); }
What will be the exact content in the HTTP response body?
Spring Boot
public ResponseEntity<String> getMessage() {
return ResponseEntity.ok("Hello World");
}Attempts:
2 left
💡 Hint
ResponseEntity.ok() sets the body to the string passed.
✗ Incorrect
The body is the string "Hello World" without quotes in the actual HTTP response body.
📝 Syntax
advanced2:00remaining
Which option correctly creates a ResponseEntity with a custom header and status 202?
You want to return a ResponseEntity with status 202 Accepted and a custom header "X-Custom" with value "Value". Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check the order of method calls on ResponseEntity builder.
✗ Incorrect
ResponseEntity.status(int) returns a builder where you can add headers before calling body(). The order matters: status() then header() then body().
🔧 Debug
advanced2:00remaining
What is the result of this ResponseEntity usage?
Analyze this Spring Boot method:
What happens when this code runs?
public ResponseEntityerrorExample() { return ResponseEntity.body("Missing status"); }
What happens when this code runs?
Spring Boot
public ResponseEntity<String> errorExample() {
return ResponseEntity.body("Missing status");
}Attempts:
2 left
💡 Hint
ResponseEntity.body(T) is a static factory method that returns 200 OK.
✗ Incorrect
ResponseEntity.body(T body) is a static factory method that creates a ResponseEntity with HTTP 200 OK and the given body. No error occurs.
🧠 Conceptual
expert3:00remaining
Which ResponseEntity usage correctly returns a 204 No Content with no body?
You want to return a response with HTTP status 204 No Content and no response body. Which code snippet correctly does this?
Attempts:
2 left
💡 Hint
204 status means no body is allowed in the response.
✗ Incorrect
ResponseEntity.noContent().build() returns a ResponseEntity with status 204 and no body, which is the correct way to send a No Content response.