0
0
Spring Bootframework~30 mins

Request mapping by method and path in Spring Boot - Mini Project: Build & Apply

Choose your learning style9 modes available
Request Mapping by Method and Path in Spring Boot
📖 Scenario: You are building a simple web service for a bookstore. The service needs to respond differently based on the HTTP method and the URL path.
🎯 Goal: Create a Spring Boot controller that maps requests by HTTP method and path. You will define a controller class, configure a base path, add methods to handle GET and POST requests at specific paths, and complete the controller with proper annotations.
📋 What You'll Learn
Create a controller class named BookController
Add a base request mapping path /books to the controller
Add a method to handle GET requests at path /list
Add a method to handle POST requests at path /add
Use correct Spring annotations for request mapping by method and path
💡 Why This Matters
🌍 Real World
Web services often need to respond differently based on HTTP method and URL path. This project shows how to set up those mappings in Spring Boot.
💼 Career
Understanding request mapping is essential for backend developers working with Spring Boot to build REST APIs.
Progress0 / 4 steps
1
Create the controller class
Create a public class named BookController annotated with @RestController.
Spring Boot
Need a hint?

Use @RestController above the class to make it a REST controller.

2
Add base request mapping path
Add a class-level @RequestMapping annotation with the path /books to the BookController class.
Spring Boot
Need a hint?

Use @RequestMapping("/books") above the class to set the base path.

3
Add GET method for listing books
Inside BookController, add a public method named listBooks that returns a String. Annotate it with @GetMapping("/list").
Spring Boot
Need a hint?

Use @GetMapping("/list") to map GET requests to /books/list.

4
Add POST method for adding a book
Inside BookController, add a public method named addBook that returns a String. Annotate it with @PostMapping("/add").
Spring Boot
Need a hint?

Use @PostMapping("/add") to map POST requests to /books/add.