0
0
Spring Bootframework~10 mins

@PostMapping for POST requests 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 create a POST endpoint using @PostMapping.

Spring Boot
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {
    @[1]("/submit")
    public String submitData() {
        return "Data submitted!";
    }
}
Drag options to blanks, or click blank then click option'
APostMapping
BRequestMapping
CDeleteMapping
DGetMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping instead of @PostMapping
Forgetting to import the correct annotation
2fill in blank
medium

Complete the code to accept POST requests at the path '/addUser'.

Spring Boot
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @[1]("/addUser")
    public String addUser() {
        return "User added!";
    }
}
Drag options to blanks, or click blank then click option'
APostMapping
BPatchMapping
CPutMapping
DGetMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping for POST requests
Using @PutMapping or @PatchMapping incorrectly
3fill in blank
hard

Fix the error in the code to correctly handle POST requests.

Spring Boot
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {
    @PostMapping("/addProduct")
    public String addProduct() {
        return "Product added!";
    }

    @[1]("/deleteProduct")
    public String deleteProduct() {
        return "Product deleted!";
    }
}
Drag options to blanks, or click blank then click option'
AGetMapping
BPostMapping
CDeleteMapping
DPutMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PostMapping for delete operations
Confusing HTTP methods and their annotations
4fill in blank
hard

Fill both blanks to create a POST endpoint that accepts JSON data and returns a confirmation.

Spring Boot
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
    @[1]("/createOrder")
    public String createOrder(@[2] String orderData) {
        return "Order received: " + orderData;
    }
}
Drag options to blanks, or click blank then click option'
APostMapping
BRequestBody
CGetMapping
DPathVariable
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping instead of @PostMapping
Forgetting @RequestBody for JSON input
5fill in blank
hard

Fill all three blanks to create a POST endpoint that accepts a JSON object, extracts a field, and returns a message.

Spring Boot
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
public class FeedbackController {
    @[1]("/submitFeedback")
    public String submitFeedback(@[2] Map<String, String> feedback) {
        String comment = feedback.get("comment");
        return "Feedback received: " + [3];
    }
}
Drag options to blanks, or click blank then click option'
APostMapping
BRequestBody
Ccomment
DPathVariable
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping instead of @PostMapping
Not using @RequestBody for JSON input
Returning the whole map instead of the comment