SlideShare a Scribd company logo
{} Coding Saint .
http://codingsaint.com | http://codingsaint.in
Spring Boot - Introduction
Overview
Spring Boot
● An easy , robust ,faster way to create
production ready spring application
● It is a very opinionated approach of
Spring boot library and third party
application with a motive of starting
an application without much
configuration.
Primary Goals of Spring Boot
● A faster way for developers to create
spring application
● Out of the box opinions to provide
defaults for spring and third party
configurations.
● Providing range of non functional
features like health checks, metrics,
embedded servers, security etc
● No code generation and no
requirement of XML configuration
Requirements and Prerequisites
As an application
Java Version 8
Maven 3.2 + or Gradle 4
Servlet Container as Tomcat 8.5 /Jetty 9.4
/Undertow 1.3
While proceeding further we do expect that
you have Java version 8, Maven 3.2 or Gradle
As a developer
Knowledge of Java
Good to have prior knowledge of Spring
Framework
Bootstrapping the first Spring Boot
Project
Spring Initializr Spring Initializr
● https://start.spring.io
First Hello World !!!
Handling a URL
Url :
http://localhost:8080/greetings
http://localhost:8080/greetings
Hello ,World
First Hello World !!!
Handling a URL
Url :
http://localhost:8080/greetings
http://localhost:8080/greetings
@RestController
public class UserController {
@RequestMapping(path="greetings",
method=RequestMethod.GET)
protected String greetings() {
return "Hello, World";
}
}
Hello ,World
@SpringBootApplication
1. @SpringBootConfiguration
2. @EnableAutoConfiguration
3. @ComponentScan
@RestController
1. Denotes that the class contains request mappings.
2. Automatically serialize and deserialize java object response to Json /XML or any format
whatever is intended.
RequestMapping in Detail
@RequestMapping(path="greetings", method=RequestMethod.GET) @RequestMapping("greetings") @GetMapping("greetings")
Configuring Database
http://localhost:8080/users
List of users
query to database
Connecting to database
Creating dataSource
Just tell Spring boot app about which database to connect.
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:file:~/user
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
application.properties
HTTP POST
● HTTP POST request : Used to create a resource on server.
● Most of the time it’s like creating INSERT(s) at database.
● POST should be used for non-idempotent request, which changes the state of
server.
HTTP POST
● HTTP POST request : Used to create a resource on server.
● Most of the time it’s like creating INSERT(s) at database.
● POST should be used for non-idempotent request, which changes the state of
server.
HTTP POST
Model
public class User {
private Long id;
private String
firstName;
private String
lastName;
private String email;
//getters and setters
}
Controller
@RequestMapping(path={"/user"}, method=RequestMethod.POST)
public ResponseEntity<Void> add(@RequestBody User
user){
//logic
}
http://localhost:8080/user
{
"firstName":"Ray",
"lastName":"McFallen",
"email":"Ray@codingsaint.com"
}
Request Body in JSON
HTTP GET
HTTP GET request : Used to get the information already present on
server/database.
GET request doesn’t change state of server but only fetch the data.
http://localhost:8080/user/1
HTTP GET
Model
public class User {
private Long id;
private String
firstName;
private String
lastName;
private String email;
//getters and setters
}
Controller
@RequestMapping(path={"/user/{id}"}, method=RequestMethod.GET)
public ResponseEntity<User> get(@PathVariable ("id")
String id){
//logic
}
http://localhost:8080/user/1
{
"id": 1,
"firstName": "Ray",
"lastName": "McFallen",
"email": "Ray@codingsaint.com"
}
Response Body in JSON
Response as User (JSON) with id
HTTP PUT
HTTP PUT request : Used to update an existing resource on server.
PUT should be used for non-idempotent request, which changes the state of
server.
HTTP PUT
Controller
@RequestMapping(path={"/user"}, method=RequestMethod.PUT)
public ResponseEntity<Void> update(@RequestBody
User user){
//logic
}
http://localhost:8080/user
{
"id": 1,
"firstName": "Tim",
"lastName": "McFallen",
"email": "Ray@codingsaint.com"
}
Request Body in JSON
HTTP DELETE
HTTP DELETE request : Used to remove/purge an existing resource on server.
DELETE should be used for non-idempotent request, which changes the state of
server.
HTTP DELETE
Controller
@RequestMapping(path={"/user/{id}"}, method=RequestMethod.DELETE)
public ResponseEntity<Void> delete(@PathVariable ("id") String id){
//logic
}
http://localhost:8080/user/1
User Information API - Introduction
{
"id": 1,
"firstName": "Ray",
"lastName": "McFallen",
"email": "Ray@codingsaint.com"
}
public class User {
private Long id;
private String firstName;
private String lastName;
private String email;
//getters and setters
}
HTTP Status Codes
Status Code Range Description
1XX Informational
2XX Success
3XX Redirect
4XX Client error
5XX Server Error
Famous HTTP Codes
200 OK
201 Created
204 No content
301 Moved permanently
400 Bad Request
401 Unauthorized
405 Method not allowed
403 Forbidden access
415 Unsupported Media Type
500 Internal server error
Learn Spring Boot REST API and Microservices:
Spring Cloud
Join us in learning Spring Boot REST API and Microservices
● More than 7000 students
● Learn Step by step Spring Boot , Microservices and Spring Cloud
● 90 % Discount and price not more than 2 cups of coffee and 1 month money back
guarantee
● Follow the link and unveil the new learning
● Spring Boot REST API and Microservices: : Spring Cloud

More Related Content

What's hot

Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
Alex Movila
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
VMware Tanzu
 
Spring boot
Spring bootSpring boot
Spring boot
Gyanendra Yadav
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
VMahesh5
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
Jakub Kubrynski
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
zeeshanhanif
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Emprovise
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
Guy Nir
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
tola99
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 
Hibernate jpa
Hibernate jpaHibernate jpa
Hibernate jpa
Lhouceine OUHAMZA
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
NexThoughts Technologies
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
Visual Engineering
 
Rest API
Rest APIRest API

What's hot (20)

Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
 
Spring boot
Spring bootSpring boot
Spring boot
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Hibernate jpa
Hibernate jpaHibernate jpa
Hibernate jpa
 
Introduction to thymeleaf
Introduction to thymeleafIntroduction to thymeleaf
Introduction to thymeleaf
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Rest API
Rest APIRest API
Rest API
 

Similar to Spring Boot and REST API

Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
Matthew Turland
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
Anuchit Chalothorn
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
Li Yi
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
Talha Ocakçı
 
03 form-data
03 form-data03 form-data
03 form-data
snopteck
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
Ivanti
 
Rest
RestRest
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
Carol McDonald
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)
Francesco Ierna
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
knight1128
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
Brandon Mueller
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
Sagara Gunathunga
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Jsp Slides
Jsp SlidesJsp Slides
Jsp Slides
DSKUMAR G
 
RESTEasy
RESTEasyRESTEasy
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
JBug Italy
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen
 

Similar to Spring Boot and REST API (20)

Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)JAVA EE DEVELOPMENT (JSP and Servlets)
JAVA EE DEVELOPMENT (JSP and Servlets)
 
03 form-data
03 form-data03 form-data
03 form-data
 
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
UEMB200: Next Generation of Endpoint Management Architecture and Discovery Se...
 
Rest
RestRest
Rest
 
Rest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.jsRest with Java EE 6 , Security , Backbone.js
Rest with Java EE 6 , Security , Backbone.js
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
SpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptxSpringBootCompleteBootcamp.pptx
SpringBootCompleteBootcamp.pptx
 
Jsp Slides
Jsp SlidesJsp Slides
Jsp Slides
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 

Recently uploaded

Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
sunnuchadda
 
Presentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptx
Presentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptxPresentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptx
Presentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptx
Er. Kushal Ghimire
 
Distillation-1.vapour liquid equilibrium
Distillation-1.vapour liquid equilibriumDistillation-1.vapour liquid equilibrium
Distillation-1.vapour liquid equilibrium
RjKing12
 
Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...
RohitGhulanavar2
 
How to Formulate A Good Research Question
How to Formulate A  Good Research QuestionHow to Formulate A  Good Research Question
How to Formulate A Good Research Question
rkpv2002
 
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATAFINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
kevig
 
Adv. Digital Signal Processing LAB MANUAL.pdf
Adv. Digital Signal Processing LAB MANUAL.pdfAdv. Digital Signal Processing LAB MANUAL.pdf
Adv. Digital Signal Processing LAB MANUAL.pdf
T.D. Shashikala
 
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagneEAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
idelewebmestre
 
李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<
李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<
李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<
amzhoxvzidbke
 
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptxIE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
BehairyAhmed2
 
The world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptxThe world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptx
engrasjadshahzad
 
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptxOME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
shanmugamram247
 
Technical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .pptTechnical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .ppt
AnkitaVerma776806
 
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
AsiimweJulius2
 
Santa Barbara City College degree offer diploma Transcript
Santa Barbara City College degree offer diploma TranscriptSanta Barbara City College degree offer diploma Transcript
Santa Barbara City College degree offer diploma Transcript
owbetho
 
ISO 9001 - 2015 Quality Management Awareness.pdf
ISO 9001 - 2015 Quality Management Awareness.pdfISO 9001 - 2015 Quality Management Awareness.pdf
ISO 9001 - 2015 Quality Management Awareness.pdf
InfoDqms
 
Probability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdfProbability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdf
utkarshakusnake
 
AI INTRODUCTION Artificial intelligence.ppt
AI INTRODUCTION Artificial intelligence.pptAI INTRODUCTION Artificial intelligence.ppt
AI INTRODUCTION Artificial intelligence.ppt
GeethaAL
 
Traffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptxTraffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptx
mailmad391
 
Generative AI and Large Language Models (LLMs)
Generative AI and Large Language Models (LLMs)Generative AI and Large Language Models (LLMs)
Generative AI and Large Language Models (LLMs)
rkpv2002
 

Recently uploaded (20)

Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
 
Presentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptx
Presentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptxPresentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptx
Presentation slide on DESIGN AND FABRICATION OF MOBILE CONTROLLED DRAINAGE.pptx
 
Distillation-1.vapour liquid equilibrium
Distillation-1.vapour liquid equilibriumDistillation-1.vapour liquid equilibrium
Distillation-1.vapour liquid equilibrium
 
Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...
 
How to Formulate A Good Research Question
How to Formulate A  Good Research QuestionHow to Formulate A  Good Research Question
How to Formulate A Good Research Question
 
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATAFINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
 
Adv. Digital Signal Processing LAB MANUAL.pdf
Adv. Digital Signal Processing LAB MANUAL.pdfAdv. Digital Signal Processing LAB MANUAL.pdf
Adv. Digital Signal Processing LAB MANUAL.pdf
 
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagneEAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
 
李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<
李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<
李易峰祝绪丹做爱视频流出【网芷:ht28.co】可爱学生妹>>>[网趾:ht28.co】]<<<
 
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptxIE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
 
The world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptxThe world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptx
 
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptxOME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
 
Technical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .pptTechnical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .ppt
 
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
1. DEE 1203 ELECTRICAL ENGINEERING DRAWING.pdf
 
Santa Barbara City College degree offer diploma Transcript
Santa Barbara City College degree offer diploma TranscriptSanta Barbara City College degree offer diploma Transcript
Santa Barbara City College degree offer diploma Transcript
 
ISO 9001 - 2015 Quality Management Awareness.pdf
ISO 9001 - 2015 Quality Management Awareness.pdfISO 9001 - 2015 Quality Management Awareness.pdf
ISO 9001 - 2015 Quality Management Awareness.pdf
 
Probability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdfProbability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdf
 
AI INTRODUCTION Artificial intelligence.ppt
AI INTRODUCTION Artificial intelligence.pptAI INTRODUCTION Artificial intelligence.ppt
AI INTRODUCTION Artificial intelligence.ppt
 
Traffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptxTraffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptx
 
Generative AI and Large Language Models (LLMs)
Generative AI and Large Language Models (LLMs)Generative AI and Large Language Models (LLMs)
Generative AI and Large Language Models (LLMs)
 

Spring Boot and REST API

  • 1. {} Coding Saint . http://codingsaint.com | http://codingsaint.in
  • 2. Spring Boot - Introduction
  • 3. Overview Spring Boot ● An easy , robust ,faster way to create production ready spring application ● It is a very opinionated approach of Spring boot library and third party application with a motive of starting an application without much configuration.
  • 4. Primary Goals of Spring Boot ● A faster way for developers to create spring application ● Out of the box opinions to provide defaults for spring and third party configurations. ● Providing range of non functional features like health checks, metrics, embedded servers, security etc ● No code generation and no requirement of XML configuration
  • 5. Requirements and Prerequisites As an application Java Version 8 Maven 3.2 + or Gradle 4 Servlet Container as Tomcat 8.5 /Jetty 9.4 /Undertow 1.3 While proceeding further we do expect that you have Java version 8, Maven 3.2 or Gradle As a developer Knowledge of Java Good to have prior knowledge of Spring Framework
  • 6. Bootstrapping the first Spring Boot Project
  • 7. Spring Initializr Spring Initializr ● https://start.spring.io
  • 8. First Hello World !!! Handling a URL Url : http://localhost:8080/greetings http://localhost:8080/greetings Hello ,World
  • 9. First Hello World !!! Handling a URL Url : http://localhost:8080/greetings http://localhost:8080/greetings @RestController public class UserController { @RequestMapping(path="greetings", method=RequestMethod.GET) protected String greetings() { return "Hello, World"; } } Hello ,World
  • 11. @RestController 1. Denotes that the class contains request mappings. 2. Automatically serialize and deserialize java object response to Json /XML or any format whatever is intended.
  • 12. RequestMapping in Detail @RequestMapping(path="greetings", method=RequestMethod.GET) @RequestMapping("greetings") @GetMapping("greetings")
  • 14. Connecting to database Creating dataSource Just tell Spring boot app about which database to connect. # H2 spring.h2.console.enabled=true spring.h2.console.path=/h2 # Datasource spring.datasource.url=jdbc:h2:file:~/user spring.datasource.username=sa spring.datasource.password= spring.datasource.driver-class-name=org.h2.Driver application.properties
  • 15. HTTP POST ● HTTP POST request : Used to create a resource on server. ● Most of the time it’s like creating INSERT(s) at database. ● POST should be used for non-idempotent request, which changes the state of server.
  • 16. HTTP POST ● HTTP POST request : Used to create a resource on server. ● Most of the time it’s like creating INSERT(s) at database. ● POST should be used for non-idempotent request, which changes the state of server.
  • 17. HTTP POST Model public class User { private Long id; private String firstName; private String lastName; private String email; //getters and setters } Controller @RequestMapping(path={"/user"}, method=RequestMethod.POST) public ResponseEntity<Void> add(@RequestBody User user){ //logic } http://localhost:8080/user { "firstName":"Ray", "lastName":"McFallen", "email":"Ray@codingsaint.com" } Request Body in JSON
  • 18. HTTP GET HTTP GET request : Used to get the information already present on server/database. GET request doesn’t change state of server but only fetch the data. http://localhost:8080/user/1
  • 19. HTTP GET Model public class User { private Long id; private String firstName; private String lastName; private String email; //getters and setters } Controller @RequestMapping(path={"/user/{id}"}, method=RequestMethod.GET) public ResponseEntity<User> get(@PathVariable ("id") String id){ //logic } http://localhost:8080/user/1 { "id": 1, "firstName": "Ray", "lastName": "McFallen", "email": "Ray@codingsaint.com" } Response Body in JSON Response as User (JSON) with id
  • 20. HTTP PUT HTTP PUT request : Used to update an existing resource on server. PUT should be used for non-idempotent request, which changes the state of server.
  • 21. HTTP PUT Controller @RequestMapping(path={"/user"}, method=RequestMethod.PUT) public ResponseEntity<Void> update(@RequestBody User user){ //logic } http://localhost:8080/user { "id": 1, "firstName": "Tim", "lastName": "McFallen", "email": "Ray@codingsaint.com" } Request Body in JSON
  • 22. HTTP DELETE HTTP DELETE request : Used to remove/purge an existing resource on server. DELETE should be used for non-idempotent request, which changes the state of server.
  • 23. HTTP DELETE Controller @RequestMapping(path={"/user/{id}"}, method=RequestMethod.DELETE) public ResponseEntity<Void> delete(@PathVariable ("id") String id){ //logic } http://localhost:8080/user/1
  • 24. User Information API - Introduction { "id": 1, "firstName": "Ray", "lastName": "McFallen", "email": "Ray@codingsaint.com" } public class User { private Long id; private String firstName; private String lastName; private String email; //getters and setters }
  • 25. HTTP Status Codes Status Code Range Description 1XX Informational 2XX Success 3XX Redirect 4XX Client error 5XX Server Error
  • 26. Famous HTTP Codes 200 OK 201 Created 204 No content 301 Moved permanently 400 Bad Request 401 Unauthorized 405 Method not allowed 403 Forbidden access 415 Unsupported Media Type 500 Internal server error
  • 27. Learn Spring Boot REST API and Microservices: Spring Cloud Join us in learning Spring Boot REST API and Microservices ● More than 7000 students ● Learn Step by step Spring Boot , Microservices and Spring Cloud ● 90 % Discount and price not more than 2 cups of coffee and 1 month money back guarantee ● Follow the link and unveil the new learning ● Spring Boot REST API and Microservices: : Spring Cloud