Challenge - 5 Problems
Request Mapping Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the HTTP response status when accessing the mapped endpoint?
Consider this Spring Boot controller method:
What will be the HTTP status code when a client sends a GET request to
@RestController
public class MyController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String greet() {
return "Hello World";
}
}What will be the HTTP status code when a client sends a GET request to
/hello?Spring Boot
@RestController public class MyController { @RequestMapping(value = "/hello", method = RequestMethod.GET) public String greet() { return "Hello World"; } }
Attempts:
2 left
💡 Hint
The method matches the GET request for the path exactly.
✗ Incorrect
The method is mapped to GET requests at path '/hello'. When a GET request is sent to '/hello', the method returns a string and Spring Boot responds with status 200 OK by default.
📝 Syntax
intermediate2:00remaining
Which option correctly maps POST requests to /submit?
You want to create a Spring Boot controller method that handles POST requests to the path
/submit. Which of the following method annotations is correct?Attempts:
2 left
💡 Hint
You need to specify both the path and the POST method explicitly.
✗ Incorrect
Option B correctly specifies the path '/submit' and the HTTP method POST. Option B uses GET instead of POST. Option B does not specify the method, so it defaults to all methods. Option B specifies POST but no path, so it won't map to '/submit'.
🔧 Debug
advanced2:00remaining
Why does this controller method cause a 405 error on POST /data?
Given this controller:
When a client sends a POST request to
@RestController
public class DataController {
@RequestMapping(value = "/data", method = RequestMethod.GET)
public String getData() {
return "Data";
}
}When a client sends a POST request to
/data, the server responds with 405 Method Not Allowed. Why?Spring Boot
@RestController public class DataController { @RequestMapping(value = "/data", method = RequestMethod.GET) public String getData() { return "Data"; } }
Attempts:
2 left
💡 Hint
Check which HTTP methods are allowed for the path.
✗ Incorrect
The controller only maps GET requests to /data. POST requests to /data have no matching handler, so Spring Boot returns 405 Method Not Allowed.
🧠 Conceptual
advanced2:00remaining
What happens if two methods map to the same path but different HTTP methods?
In a Spring Boot controller, you have:
What happens when a client sends a GET request and a POST request to
@RequestMapping(value = "/item", method = RequestMethod.GET)
public String getItem() { return "Get"; }
@RequestMapping(value = "/item", method = RequestMethod.POST)
public String postItem() { return "Post"; }What happens when a client sends a GET request and a POST request to
/item?Spring Boot
@RequestMapping(value = "/item", method = RequestMethod.GET) public String getItem() { return "Get"; } @RequestMapping(value = "/item", method = RequestMethod.POST) public String postItem() { return "Post"; }
Attempts:
2 left
💡 Hint
Spring Boot matches methods by both path and HTTP method.
✗ Incorrect
Spring Boot allows multiple methods mapped to the same path if they differ by HTTP method. GET requests call getItem(), POST requests call postItem().
❓ state_output
expert2:00remaining
What is the response body when sending a PUT request to /update with this controller?
Given this Spring Boot controller:
What will be the response body when a client sends a PUT request to
@RestController
public class UpdateController {
@RequestMapping(value = "/update", method = {RequestMethod.POST, RequestMethod.PUT})
public String update() {
return "Updated";
}
}What will be the response body when a client sends a PUT request to
/update?Spring Boot
@RestController public class UpdateController { @RequestMapping(value = "/update", method = {RequestMethod.POST, RequestMethod.PUT}) public String update() { return "Updated"; } }
Attempts:
2 left
💡 Hint
The method handles both POST and PUT requests.
✗ Incorrect
The method is mapped to both POST and PUT requests at /update. A PUT request will invoke this method and return "Updated" as the response body.