Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a GET endpoint using @GetMapping.
Spring Boot
public class HelloController { @[1]("/hello") public String sayHello() { return "Hello, world!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PostMapping instead of @GetMapping
Forgetting the annotation entirely
✗ Incorrect
The @GetMapping annotation is used to map HTTP GET requests to the method.
2fill in blank
mediumComplete the code to specify the path for the GET request.
Spring Boot
@GetMapping(path = "[1]") public String greet() { return "Hi!"; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash
Using uppercase letters in path inconsistently
✗ Incorrect
The path should start with a slash / to define the endpoint URL correctly.
3fill in blank
hardFix the error in the annotation to correctly map a GET request.
Spring Boot
@[1]("/welcome") public String welcome() { return "Welcome!"; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase letters in annotation name
Using @PostMapping by mistake
✗ Incorrect
The annotation is case-sensitive and must be exactly @GetMapping.
4fill in blank
hardFill both blanks to create a GET endpoint that returns a greeting message.
Spring Boot
public class GreetingController { @[1]([2] = "/greet") public String greet() { return "Hello!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PostMapping instead of @GetMapping
Using an incorrect attribute name
✗ Incorrect
@GetMapping is the correct annotation and value is the common attribute to specify the path.
5fill in blank
hardFill all three blanks to create a GET endpoint with a path and a method returning a string.
Spring Boot
public class MyController { @[1]([2] = "/hello") public [3] sayHello() { return "Hello!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PostMapping instead of @GetMapping
Using 'value' instead of 'path' attribute
Wrong return type
✗ Incorrect
The method is annotated with @GetMapping using the path attribute, and the return type is String.