Build Spring Boot REST API | GET and POST Methods | Chapter #3

Опубликовано: 12 Октябрь 2024
на канале: Genuine Coder
12,808
148

In this tutorial, we will learn how to create REST API using spring boot. We will create two endpoints. One GET endpoint for getting all the employee objects from the server and one POST endpoint for accepting new employees that need to be saved.

For marking a class as a REST Controller, spring provides an annotation "@RestController". Then we can write functions in the class that creates new Restful API endpoints.

For creating a GET endpoint, we will use @GetMapping annotation. Within the annotation, we will give the URL we would like to have for the endpoint. Similarly, for creating a POST endpoint, we will use @PostMapping annotation.

Once the endpoints are created, we will test them using the Postman tool.

You can find this project in GitHub at https://github.com/afsalashyana/Sprin...
Genuine Coder Blog: https://www.genuinecoder.com/

Tags: #Java #SpringBoot

Introduction: (0:00)
Create new Rest Controller class: (1:33)
Create GET endpoint: (4:04)
Test GET endpoint with Postman: (8:55)
Create POST endpoint: (11:46)
Test POST endpoint with Postman: (14:00)
Improve POST endpoint by returning Employee object: (17:34)