#65 🌐 Web Service Layer | Part 6 — 🌱 Spring Web | @PostMapping & @RequestBody
3IA Community
0:00 / 0:00
#65 🌐 Web Service Layer | Part 6 — 🌱 Spring Web | @PostMapping & @RequestBody
29 просмотров · 11 дней назад
3IA Community
346 подписчиков
29 просмотров · 11 дней назад
#65 🌐 Web Service Layer | Part 6 — 🌱 Spring Web | @PostMapping & @RequestBody
Description:
In this video, we continue our exploration of the Web Service Layer with Spring Web and Spring Boot.
After seeing in the previous video how to use @GetMapping and @RequestParam to retrieve information from HTTP request parameters, we will now discover how to send data to a REST API with an HTTP POST request.
We will explore the role of @PostMapping and @RequestBody, and understand how Spring Boot automatically transforms the JSON received in the HTTP body into a Java object.
This video covers:
• Understanding the role of @PostMapping
• Understanding how @RequestBody works
• Binding an HTTP JSON object to a Java object
• Sending a Product object in the body of a POST request
• Creating an endpoint to save a product with save()
• Creating an endpoint to save multiple products with saveAll()
• Understanding the difference between save() and saveAll()
• Using consumes and produces
• Testing HTTP POST requests with a JSON body
• Understanding the relationship between HTTP POST, JSON, @RequestBody, and the Controller
Example Product save():
{
"name": "Smartwatch",
"price": 8500.0,
"category": "Electronics",
"available": true,
"stock": 10
}
Example Product saveAll():
[
{
"name": "MacBook Pro",
"price": 15000.0,
"category": "Computer",
"available": true,
"stock": 25
},
{
"name": "Asus ROG",
"price": 12000.0,
"category": "Computer",
"available": true,
"stock": 15
},
{
"name": "Xiaomi Redmi Note 14",
"price": 3200.0,
"category": "Smartphone",
"available": true,
"stock": 60
}
GitHub source code:
https://github.com/3ia-community/Form...
Video objectives:
✔ Understand how @PostMapping works
✔ Understand the role of @RequestBody
✔ Bind JSON to Java objects
✔ Send data to the body of a request POST
✔ Create a save() endpoint for a product
✔ Create a saveAll() endpoint for multiple products
✔ Understand consumes and produces
✔ Test HTTP POST requests with JSON
✔ Understand the relationship between HTTP POST, JSON, and the Controller
✔ Put @PostMapping into practice with Spring Boot
Contact me:
📧 mohammedezzaim00@gmail.com
💼 / mohammed-ezzaim
🐱 https://github.com/mohammed-ezzaim
Keywords & Hashtags:
#SpringWeb #SpringWebMVC #SpringBoot #PostMapping #RequestBody #GetMapping #RequestParam #PathVariable #RESTAPI #REST #Java #BackendDevelopment #JavaDeveloper #SpringBootTutorial #API #HTTP #HTTPPOST #WebService #JSON #MySQL #JPA #QueryParameters #3IACommunity