Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to map a GET request to the path "/hello".
Spring Boot
@RestController public class HelloController { @RequestMapping(value = "/hello", method = RequestMethod.[1]) public String sayHello() { return "Hello!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for retrieving data.
Omitting the method attribute, which defaults to all methods.
✗ Incorrect
The @RequestMapping annotation uses method = RequestMethod.GET to handle GET requests.
2fill in blank
mediumComplete the code to map a POST request to the path "/submit".
Spring Boot
@RestController public class SubmitController { @RequestMapping(value = "/submit", method = RequestMethod.[1]) public String submitData() { return "Submitted!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for data submission.
Confusing PATCH with POST.
✗ Incorrect
The POST method is used to submit data to the server.
3fill in blank
hardFix the error in the code to correctly map a DELETE request to "/remove".
Spring Boot
@RestController public class RemoveController { @RequestMapping(value = "/remove", method = RequestMethod.[1]) public String removeItem() { return "Removed!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET or POST instead of DELETE for removal.
Forgetting to specify the method attribute.
✗ Incorrect
DELETE method is used to remove resources at the specified path.
4fill in blank
hardFill both blanks to map a PUT request to "/update" and specify the method correctly.
Spring Boot
@RestController public class UpdateController { @RequestMapping(value = [1], method = RequestMethod.[2]) public String updateItem() { return "Updated!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong path string or missing quotes.
Using GET instead of PUT for updates.
✗ Incorrect
The path should be "/update" and the method PUT for updating resources.
5fill in blank
hardFill all three blanks to map a PATCH request to "/modify", specify the method, and return a response.
Spring Boot
@RestController public class ModifyController { @RequestMapping(value = [1], method = RequestMethod.[2]) public String modifyItem() { return [3]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong HTTP method for partial updates.
Forgetting quotes around strings.
✗ Incorrect
The path is "/modify", the method is PATCH, and the return string is "Modified!".