0
0
Spring Bootframework~10 mins

Why understanding request flow matters in Spring Boot - Test Your Understanding

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

Complete the code to define a Spring Boot controller method that handles GET requests.

Spring Boot
@RestController
public class HelloController {
    @GetMapping("/hello")
    public String sayHello() {
        return [1];
    }
}
Drag options to blanks, or click blank then click option'
A"Hello World"
BHello World
Creturn "Hello World"
DSystem.out.println("Hello World")
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using print statements instead of return
2fill in blank
medium

Complete the code to extract a path variable named 'id' in a Spring Boot controller method.

Spring Boot
@GetMapping("/item/[1]")
public String getItem(@PathVariable String id) {
    return "Item: " + id;
}
Drag options to blanks, or click blank then click option'
A:id
B<id>
C{id}
D(id)
Attempts:
3 left
💡 Hint
Common Mistakes
Using colon or angle brackets instead of braces
Mismatching variable names
3fill in blank
hard

Fix the error in the code to correctly map a POST request with a JSON body to a Java object.

Spring Boot
@PostMapping("/add")
public ResponseEntity<String> addItem([1] Item item) {
    // process item
    return ResponseEntity.ok("Added");
}
Drag options to blanks, or click blank then click option'
A@PathVariable
B@RequestParam
C@ResponseBody
D@RequestBody
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PathVariable or @RequestParam instead of @RequestBody
Omitting the annotation
4fill in blank
hard

Fill both blanks to create a Spring Boot controller method that handles PUT requests and returns a ResponseEntity with status 204.

Spring Boot
@PutMapping("/update/[1]")
public ResponseEntity<Void> updateItem(@PathVariable String id, @RequestBody Item item) {
    // update logic
    return ResponseEntity.[2]();
}
Drag options to blanks, or click blank then click option'
A{id}
BnoContent
Cok
Dcreated
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong path variable syntax
Returning wrong ResponseEntity status
5fill in blank
hard

Fill all three blanks to create a Spring Boot controller method that handles DELETE requests, extracts an 'id' path variable, and returns a ResponseEntity with status 200 and a message.

Spring Boot
@DeleteMapping("/delete/[1]")
public ResponseEntity<String> deleteItem(@PathVariable String [2]) {
    // delete logic
    return ResponseEntity.[3]("Deleted item " + [2]);
}
Drag options to blanks, or click blank then click option'
Aid
Bok
CitemId
Dcreated
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatched variable names
Using wrong ResponseEntity status method