0
0
Spring Bootframework~10 mins

Request mapping by method and path in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AGET
BPOST
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for retrieving data.
Omitting the method attribute, which defaults to all methods.
2fill in blank
medium

Complete 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'
AGET
BPATCH
COPTIONS
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for data submission.
Confusing PATCH with POST.
3fill in blank
hard

Fix 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'
APUT
BDELETE
CGET
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET or POST instead of DELETE for removal.
Forgetting to specify the method attribute.
4fill in blank
hard

Fill 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'
A"/update"
B"/edit"
CGET
DPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong path string or missing quotes.
Using GET instead of PUT for updates.
5fill in blank
hard

Fill 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'
A"/modify"
BPATCH
C"Modified!"
D"/change"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong HTTP method for partial updates.
Forgetting quotes around strings.