HTTP Status Codes in REST — Spring Technical Interview Questions & Answers
Choosing 200/201/400/404/500 correctly.
HTTP Status Codes in REST
- Status codes tell the client what happened.
- 200 OK: success read/update style responses.
- 201 Created: successful create.
- 400 Bad Request: client sent invalid data.
- 404 Not Found: resource missing.
- 500 Internal Server Error: unexpected server failure.
- Never return 200 for every case — pick the honest code.
Technical Interview Tip: Match create→201 and missing→404 in examples.
Code Examples for HTTP Status Codes in REST
HTTP Status Codes in REST — working example
// Topic: HTTP Status Codes in REST
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
class TopicController {
@GetMapping("/api/topic")
String topic() {
return "Spring Boot: HTTP Status Codes in REST";
}
}HTTP Status Codes in REST: GET /api/topic returns this title string.
How to Explain HTTP Status Codes in REST to an Interviewer
What is HTTP Status Codes in REST (sb)?
Used for GET /api/marks/{roll} a campus API Not just the heading
Give one small example of HTTP Status Codes in REST (sb).
@RestController + service call Choosing 200/201/400/404/500 correctly
What mistake do beginners make with HTTP Status Codes in REST (sb)?
business logic inside the controller Show the fix
Where do you use HTTP Status Codes in REST (sb)?
a campus API GET /api/marks/{roll}