-
Notifications
You must be signed in to change notification settings - Fork 0
Restful Web Services with Spring Boot Part I
Amitha R edited this page Dec 19, 2020
·
8 revisions
- start.spring.io
- Provide details:
- Maven Project, Java, SpringBoot - 2.0.0(SNAPSHOT)
- Group : com.example.project
- Artifact : restful-web-services
- dependencies : Web , DevTools, JPA, H2
-
Generate Project
-
For any Maven project need to specify a group id and artifact id.
-
Spring Initializer creates a Maven Project, puts it in a Zip and downloaded to the downloads folder.
-
In eclipse -> Import -> Existing Maven Project
- Load the maven project.
- Maven would download all the dependencies listed in the pom.xml file.
- REST is a style of software architecture for distributed hypermedia systems (design resources and how you expose them using HTTP).
- REST makes best use of HTTP.
- Key abstraction is a resource - each resource has a URI. ** (Users (1) - Posts(Many))
- Different RESTful Web services we would create.
- Retrieve all Users - GET /users
- Create a User - POST /users
- Retrieve one User - GET /users/{id} -> /users/1
- Delete a User - DELETE /users/{id} -> /users/1
- Retrieve all posts for a User - GET /users/{id}/posts
- Create posts for a User - POST /users/{id}/posts
- Retrieve details of a post - GET /users/{id}/posts/{post_id}
- returns a getmapping request.
- Class object that in turn returns a String.
- Getter, Setter and toString Method.
- Without a Getter - encounter an error - No converter found for return value of type.
logging.level.org.springframework = debug
- AUTO-CONFIGURATION REPORT
- Consists of a lot of details.
- Configuration of Dispatcher Servlet.
- All the configurations are getting fired because of Spring boot auto configuration
- Spring boot looks at all the classes, all the jars which are available on the classpath and auto configures different things like dispatcher servlet.
- HTTP message converters - bean is automatically converted to JSON.
- Jackson to object mapper - converted from JSON to bean and bean to JSON.
- Who is configuring dispatcher servlet?
- Spring Boot Auto configure
- How does the HelloWorldBean object get converted to JSON?
- Jackson to object mapper
- Who is configuring the error mapping?
- Spring Boot Auto Configuration.
- Dispatcher Servlet is handling all the requests. (/)
- Follows a pattern called front controller.
- Dispatcher Servlet is the front controller for Spring MVC framework.
- Dispatcher Servlet knows the various mappings present in the application.
- Once the dispatcher servlet gets the request, it determines which is the right controller to execute that request.
- Once the bean is returned, dispatcher servlet looks at how do I send the response back.
- Dispatcher Servlet will make use of Jackson to perform the conversion to JSON.
- The helloworldbean is converted to JSON and sent back.
- HATEOS : Hypermedia as the engine of application state.
- In POM.xml file add the following dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>