0
0
Spring Bootframework~20 mins

ResponseEntity for full response control in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ResponseEntity Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the HTTP status code returned by this Spring Boot controller method?
Consider this Spring Boot controller method using ResponseEntity:
public ResponseEntity greet() {
    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");
}
A200 OK
B201 Created
C404 Not Found
D500 Internal Server Error
Attempts:
2 left
💡 Hint
Look at the status method used in ResponseEntity.
state_output
intermediate
2:00remaining
What is the response body content returned here?
Given this Spring Boot controller method:
public ResponseEntity getMessage() {
    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");
}
AHello World
B"Hello World"
Cnull
DAn empty string
Attempts:
2 left
💡 Hint
ResponseEntity.ok() sets the body to the string passed.
📝 Syntax
advanced
2: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?
Areturn ResponseEntity.status(202).header("X-Custom", "Value").body("Accepted");
Breturn ResponseEntity.header("X-Custom", "Value").status(202).body("Accepted");
Creturn ResponseEntity.body("Accepted").status(202).header("X-Custom", "Value");
Dreturn ResponseEntity.body("Accepted").header("X-Custom", "Value").status(202);
Attempts:
2 left
💡 Hint
Check the order of method calls on ResponseEntity builder.
🔧 Debug
advanced
2:00remaining
What is the result of this ResponseEntity usage?
Analyze this Spring Boot method:
public ResponseEntity errorExample() {
    return ResponseEntity.body("Missing status");
}

What happens when this code runs?
Spring Boot
public ResponseEntity<String> errorExample() {
    return ResponseEntity.body("Missing status");
}
ACompilation error: body() is not a static method
BCompilation error: missing import for ResponseEntity
CRuntime NullPointerException
DReturns HTTP 200 with body "Missing status"
Attempts:
2 left
💡 Hint
ResponseEntity.body(T) is a static factory method that returns 200 OK.
🧠 Conceptual
expert
3: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?
Areturn ResponseEntity.status(204).body(null);
Breturn ResponseEntity.status(204).body("");
Creturn ResponseEntity.noContent().build();
Dreturn ResponseEntity.ok().body(null);
Attempts:
2 left
💡 Hint
204 status means no body is allowed in the response.