5 Unit5 Part2
5 Unit5 Part2
Using REST
API
Introduction
Spring Boot is a project that is built on top of the Spring Framework.
It provides an easier and faster way to set up, configure, and run
both simple and web-based applications.
It is a Spring module that provides the RAD (Rapid Application
Development) feature to the Spring Framework used to create a
stand-alone Spring-based application that you can just run because it
needs minimal Spring configuration.
As summarized in the below figure, Spring Boot is the
combination of Spring Framework and Embedded
Servers.
Spring Boot Architecture
Spring Boot uses all the modules of Spring-like Spring MVC, Spring Data, etc. The architecture of Spring
Boot is the same as the architecture of Spring MVC, except for one thing: there is no need for DAO and
DAOImpl classes in Spring boot. As a summary, in a simple spring boot flow:
•Data access layer gets created and CRUD operations are performed.
•The client makes the HTTP requests.
•The request goes to the controller, and the controller maps that request and handles it. After that, it calls
the service logic if required.
•In the service layer, all the business logic performs. It performs the logic on the data that is mapped to JPA
with model classes.
•A response page is returned to the user if no error occurs.
Spring Boot Architecture
Spring Boot Annotations
Properties file
•GET https://www.facebook.com/prashant.tomer.946/
My profile is a single resource available on Facebook. I can view a representation of that resource in
HTML using that URL in my web browser. I can also view another representation of it using the
Facebook Graph API.
•GET https://graph.facebook.com/v7.0/me
Rest API
This is just one resource Facebook provides, offering up a buffet of digital resources for me to
consume as a developer.
Now, Apply @GetMapping annotation to create an end point to access this controller, given below is
code:
Run Application
To test your REST end point, need to run your springboot application and check on which port your
application is running (check console and analyse the output , port number is also there), now go
to browser and access using your end point name:
Other endPoint
RequestMapping and
ResponseBody
In Spring Boot, @RequestMapping is a core annotation used to map HTTP requests to handler
methods in your application's controllers. It allows you to define how incoming requests should be
handled based on the request URL, HTTP method, request parameters, headers, and more.
Here’s a detailed guide on using @RequestMapping in Spring Boot:
PathVariable
You can capture parts of the URL as variables using curly braces {}:
@ResponseBody
}
Request Param
In Spring Boot, handling request parameters involves retrieving data sent by the client as part of
the URL query string or as form data in a POST request. Spring provides several ways to access
request parameters in your controller methods. Let's explore how you can work with request
parameters using @RequestParam, HttpServletRequest, and @PathVariable.
Thank You