SlideShare a Scribd company logo
Restful applications using Spring MVC




Kamal Govindraj
TenXperts Technologies
About Me
   Programming for 13 Years
   Architect @ TenXperts Technologies
   Trainer / Consultant @ SpringPeople
    Technologies
   Enteprise applications leveraging open source
    frameworks (spring,hibernate, gwt,jbpm..)
   Key contributor to InfraRED & Grails jBPM
    plugin (open source)
Agenda
   What is REST?
   REST Concepts
   RESTful Architecture Design
   Spring @MVC
   Implement REST api using Spring @MVC 3.0
What is REST?
   Representational State Transfer
   Term coined up by Roy Fielding
    −   Author of HTTP spec
   Architectural style
   Architectural basis for HTTP
    −   Defined a posteriori
Core REST Concepts
 Identifiable Resources
 Uniform interface

 Stateless conversation

 Resource representations

 Hypermedia
Identifiable Resources
   Everything is a resource
    −   Customer
    −   Order
    −   Catalog Item
   Resources are accessed by URIs
Uniform interface
   Interact with Resource using single, fixed
    interface
   GET /orders - fetch list of orders
   GET /orders/1 - fetch order with id 1
   POST /orders – create new order
   PUT /orders/1 – update order with id 1
   DELETE /orders/1 – delete order with id 1
   GET /customers/1/order – all orders for
    customer with id 1
Resource representations
   More that one representation possible
    −   text/html, image/gif, application/pdf
   Desired representation set in Accept HTTP
    header
    −   Or file extension
   Delivered representation show in Content-
    Type
   Access resources through representation
   Prefer well-known media types
Stateless conversation
   Server does not maintain state
    −   Don’t use the Session!
   Client maintains state through links
   Very scalable
   Enforces loose coupling (no shared session
    knowledge)
Hypermedia
   Resources contain links
   Client state transitions are made through these links
   Links are provided by server
   Example

    <oder ref=”/order/1”>
        <customer ref=”/customers/1”/>
        <lineItems>
             <lineItem item=”/catalog/item/125” qty=”10”/>
             <lineItem item=”/catalog/item/150” qty=”5”>
        </lineItems>
    </oder>
RESTful Architecture
RESTful application design
   Identify resources
    −   Design URIs
   Select representations
    −   Or create new ones
   Identify method semantics
   Select response codes
Implement Restful API using Spring MVC
Spring @MVC
@Controller
public class AccountController {
     @Autowired AccountService accountService;

     @RequestMapping("/details")
     public String details(@RequestParam("id")Long id,
                     Model model) {
          Account account = accountService.findAccount(id);
          model.addAttribute(account);
          return "account/details";
     }
}

account/details.jsp
    <h1>Account Details</h1>
    <p>Name : ${account.name}</p>
    <p>Balance : ${account.balance}</p>

../details?id=1
RESTful support in Spring 3.0
   Extends Spring @MVC to handle URL
    templates - @PathVariable
   Leverages Spring OXM module to provide
    marshalling / unmarshalling (castor, xstream,
    jaxb etc)
   @RequestBody – extract request body to
    method parameter
   @ResponseBody – render return value to
    response body using converter – no views
    required
REST controller
@Controller public class AccountController {

      @RequestMapping(value="/accounts",method=RequestMethod.GET)
      @ResponseBody public AccountList getAllAcccount() {
      }

      @RequestMapping(value="/accounts/${id}",method=RequestMethod.GET)
      @ResponseBody public Account getAcccount(@PathVariable("id")Long id) {
      }

      @RequestMapping(value="/accounts/",method=RequestMethod.POST)
      @ResponseBody public Long createAcccount(@RequestBody Account account) {
      }

      @RequestMapping(value="/accounts/${id}",method=RequestMethod.PUT)
      @ResponseBody public Account updateAcccount(@PathVariable("id")Long id, @RequestBody Account account) {
      }

      @RequestMapping(value="/accounts/${id}",method=RequestMethod.DELETE)
      @ResponseBody public void deleteAcccount(@PathVariable("id")Long id) {
      }
}
web.xml

<servlet>
    <servlet-name>rest-api</servlet-name>
    <servlet-class>org....web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>rest-api</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
rest-api-servlet-context.xml

<bean id="marshaller" class="...oxm.xstream.XStreamMarshaller">
   <property name="aliases">
       <map>
          <entry key="category" value="...domain.Category"/>
          <entry key="catalogItem" value="...domain.CatalogItem"/>
       </map>
   </property>
</bean>
rest-api-servlet-context.xml
<bean
    class="...mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <util:list>
              <bean
                    class="...http.converter.xml.MarshallingHttpMessageConverter">
                    <constructor-arg ref="marshaller" />
              </bean>
              <bean
                    class="...http.converter.StringHttpMessageConverter" />
        </util:list>
    </property>
</bean>
Invoke REST services
   The new RestTemplate class provides client-
    side invocation of a RESTful web-service
     HTTP                       RestTemplate Method
    Method
    DELETE    delete(String url, String... urlVariables)
    GET       getForObject(String url, Class<t> responseType, String …
              urlVariables)
    HEAD      headForHeaders(String url, String… urlVariables)
    OPTIONS   optionsForAllow(String url, String… urlVariables)
    POST      postForLocation(String url, Object request, String…
              urlVariables)

    PUT       put(String url, Object request, String…urlVariables)
REST template example

AccountList accounts = restTemplate.getForObject("/accounts/",AccountList.class);

Account account = restTemplate.getForObject("/accounts/${id}",Account.class ,"1");

restTemplate.postForLocation("/accounts/", account);

restTemplate.put("/accounts/${id}",account,"1");

restTemplate.delete("/accounts/${id}", "1");
Demo
Questions?
Thank You

More Related Content

What's hot (20)

PPTX
Java Constructor
MujtabaNawaz4
 
PDF
Nestjs MasterClass Slides
Nir Kaufman
 
PDF
Hibernate Presentation
guest11106b
 
PDF
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
PPTX
Java Lambda Expressions.pptx
SameerAhmed593310
 
PDF
Clean backends with NestJs
Aymene Bennour
 
PPSX
Strings in Java
Hitesh-Java
 
PDF
Lambda Expressions in Java
Erhan Bagdemir
 
PDF
Java: The Complete Reference, Eleventh Edition
moxuji
 
PDF
REST APIs with Spring
Joshua Long
 
PDF
Angular Directives
iFour Technolab Pvt. Ltd.
 
PDF
Spring Data JPA
Cheng Ta Yeh
 
PDF
spring-api-rest.pdf
Jaouad Assabbour
 
PPTX
Spring Boot and REST API
07.pallav
 
PPT
Hibernate
Ajay K
 
PPTX
Java database connectivity with MySql
Dhyey Dattani
 
PDF
Spring Boot
HongSeong Jeon
 
PDF
Spring annotation
Rajiv Srivastava
 
PPT
Spring Core
Pushan Bhattacharya
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
Java Constructor
MujtabaNawaz4
 
Nestjs MasterClass Slides
Nir Kaufman
 
Hibernate Presentation
guest11106b
 
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
Java Lambda Expressions.pptx
SameerAhmed593310
 
Clean backends with NestJs
Aymene Bennour
 
Strings in Java
Hitesh-Java
 
Lambda Expressions in Java
Erhan Bagdemir
 
Java: The Complete Reference, Eleventh Edition
moxuji
 
REST APIs with Spring
Joshua Long
 
Angular Directives
iFour Technolab Pvt. Ltd.
 
Spring Data JPA
Cheng Ta Yeh
 
spring-api-rest.pdf
Jaouad Assabbour
 
Spring Boot and REST API
07.pallav
 
Hibernate
Ajay K
 
Java database connectivity with MySql
Dhyey Dattani
 
Spring Boot
HongSeong Jeon
 
Spring annotation
Rajiv Srivastava
 
Spring Core
Pushan Bhattacharya
 
Spring boot Introduction
Jeevesh Pandey
 

Viewers also liked (20)

PDF
RESTful Web Services with Spring MVC
digitalsonic
 
PDF
Spring Web Services: SOAP vs. REST
Sam Brannen
 
PDF
Microservices with Spring Boot
Joshua Long
 
PDF
RESTful Web Services
Christopher Bartling
 
PDF
Java 8 - New Features
Rafael Brito de Oliveira
 
PDF
That old Spring magic has me in its SpEL
Craig Walls
 
KEY
Modular Java - OSGi
Craig Walls
 
PDF
Spring boot
Bhagwat Kumar
 
PDF
Java Configuration Deep Dive with Spring
Joshua Long
 
PDF
Boot It Up
Joshua Long
 
PPT
Spring MVC
Abdelhakim Bachar
 
PPTX
Level 3 REST Makes Your API Browsable
Matt Bishop
 
PPT
Spring Boot in Action
Alex Movila
 
PDF
Spring MVC
Roman Pichlík
 
PDF
Spring MVC - Web Forms
Ilio Catallo
 
PDF
Testing Spring MVC and REST Web Applications
Sam Brannen
 
PPTX
REST Enabling Your Oracle Database
Jeff Smith
 
PPTX
Make Your API Irresistible
duvander
 
PPTX
Soap and restful webservice
Dong Ngoc
 
PPT
Struts 2 + Spring
Bryan Hsueh
 
RESTful Web Services with Spring MVC
digitalsonic
 
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Microservices with Spring Boot
Joshua Long
 
RESTful Web Services
Christopher Bartling
 
Java 8 - New Features
Rafael Brito de Oliveira
 
That old Spring magic has me in its SpEL
Craig Walls
 
Modular Java - OSGi
Craig Walls
 
Spring boot
Bhagwat Kumar
 
Java Configuration Deep Dive with Spring
Joshua Long
 
Boot It Up
Joshua Long
 
Spring MVC
Abdelhakim Bachar
 
Level 3 REST Makes Your API Browsable
Matt Bishop
 
Spring Boot in Action
Alex Movila
 
Spring MVC
Roman Pichlík
 
Spring MVC - Web Forms
Ilio Catallo
 
Testing Spring MVC and REST Web Applications
Sam Brannen
 
REST Enabling Your Oracle Database
Jeff Smith
 
Make Your API Irresistible
duvander
 
Soap and restful webservice
Dong Ngoc
 
Struts 2 + Spring
Bryan Hsueh
 
Ad

Similar to Building RESTful applications using Spring MVC (20)

PPTX
Rest with Java EE 6 , Security , Backbone.js
Carol McDonald
 
PPTX
Rest
Carol McDonald
 
PDF
JAX-RS JavaOne Hyderabad, India 2011
Shreedhar Ganapathy
 
PPTX
RESTful Web Services
Gordon Dickens
 
PDF
RESTful Web services using JAX-RS
Arun Gupta
 
PDF
Ws rest
patriknw
 
PDF
Spark IT 2011 - Developing RESTful Web services with JAX-RS
Arun Gupta
 
PPTX
Restful webservices
Luqman Shareef
 
PPTX
Overview of RESTful web services
nbuddharaju
 
PPTX
Rest presentation
srividhyau
 
PDF
Restful Services
SHAKIL AKHTAR
 
PDF
RESTful web
Alvin Qi
 
PPTX
Restful web services with java
Vinay Gopinath
 
PPTX
6 Months Industrial Training in Spring Framework
Arcadian Learning
 
PDF
Doing REST Right
Kerry Buckley
 
PPSX
Restful web services rule financial
Rule_Financial
 
PDF
Rest web services
Paulo Gandra de Sousa
 
ODP
RESTful Web Services with JAX-RS
Carol McDonald
 
PPTX
JAX-RS 2.0 and OData
Anil Allewar
 
PPTX
JAX-RS. Developing RESTful APIs with Java
Jerry Kurian
 
Rest with Java EE 6 , Security , Backbone.js
Carol McDonald
 
JAX-RS JavaOne Hyderabad, India 2011
Shreedhar Ganapathy
 
RESTful Web Services
Gordon Dickens
 
RESTful Web services using JAX-RS
Arun Gupta
 
Ws rest
patriknw
 
Spark IT 2011 - Developing RESTful Web services with JAX-RS
Arun Gupta
 
Restful webservices
Luqman Shareef
 
Overview of RESTful web services
nbuddharaju
 
Rest presentation
srividhyau
 
Restful Services
SHAKIL AKHTAR
 
RESTful web
Alvin Qi
 
Restful web services with java
Vinay Gopinath
 
6 Months Industrial Training in Spring Framework
Arcadian Learning
 
Doing REST Right
Kerry Buckley
 
Restful web services rule financial
Rule_Financial
 
Rest web services
Paulo Gandra de Sousa
 
RESTful Web Services with JAX-RS
Carol McDonald
 
JAX-RS 2.0 and OData
Anil Allewar
 
JAX-RS. Developing RESTful APIs with Java
Jerry Kurian
 
Ad

More from IndicThreads (20)

PPTX
Http2 is here! And why the web needs it
IndicThreads
 
ODP
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
IndicThreads
 
PPT
Go Programming Language - Learning The Go Lang way
IndicThreads
 
PPT
Building Resilient Microservices
IndicThreads
 
PPT
App using golang indicthreads
IndicThreads
 
PDF
Building on quicksand microservices indicthreads
IndicThreads
 
PDF
How to Think in RxJava Before Reacting
IndicThreads
 
PPT
Iot secure connected devices indicthreads
IndicThreads
 
PDF
Real world IoT for enterprises
IndicThreads
 
PPT
IoT testing and quality assurance indicthreads
IndicThreads
 
PPT
Functional Programming Past Present Future
IndicThreads
 
PDF
Harnessing the Power of Java 8 Streams
IndicThreads
 
PDF
Building & scaling a live streaming mobile platform - Gr8 road to fame
IndicThreads
 
PPTX
Internet of things architecture perspective - IndicThreads Conference
IndicThreads
 
PDF
Cars and Computers: Building a Java Carputer
IndicThreads
 
PPTX
Scrap Your MapReduce - Apache Spark
IndicThreads
 
PPT
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
PPTX
Speed up your build pipeline for faster feedback
IndicThreads
 
PPT
Unraveling OpenStack Clouds
IndicThreads
 
PPTX
Digital Transformation of the Enterprise. What IT leaders need to know!
IndicThreads
 
Http2 is here! And why the web needs it
IndicThreads
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
IndicThreads
 
Go Programming Language - Learning The Go Lang way
IndicThreads
 
Building Resilient Microservices
IndicThreads
 
App using golang indicthreads
IndicThreads
 
Building on quicksand microservices indicthreads
IndicThreads
 
How to Think in RxJava Before Reacting
IndicThreads
 
Iot secure connected devices indicthreads
IndicThreads
 
Real world IoT for enterprises
IndicThreads
 
IoT testing and quality assurance indicthreads
IndicThreads
 
Functional Programming Past Present Future
IndicThreads
 
Harnessing the Power of Java 8 Streams
IndicThreads
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
IndicThreads
 
Internet of things architecture perspective - IndicThreads Conference
IndicThreads
 
Cars and Computers: Building a Java Carputer
IndicThreads
 
Scrap Your MapReduce - Apache Spark
IndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
Speed up your build pipeline for faster feedback
IndicThreads
 
Unraveling OpenStack Clouds
IndicThreads
 
Digital Transformation of the Enterprise. What IT leaders need to know!
IndicThreads
 

Recently uploaded (20)

PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 

Building RESTful applications using Spring MVC

  • 1. Restful applications using Spring MVC Kamal Govindraj TenXperts Technologies
  • 2. About Me  Programming for 13 Years  Architect @ TenXperts Technologies  Trainer / Consultant @ SpringPeople Technologies  Enteprise applications leveraging open source frameworks (spring,hibernate, gwt,jbpm..)  Key contributor to InfraRED & Grails jBPM plugin (open source)
  • 3. Agenda  What is REST?  REST Concepts  RESTful Architecture Design  Spring @MVC  Implement REST api using Spring @MVC 3.0
  • 4. What is REST?  Representational State Transfer  Term coined up by Roy Fielding − Author of HTTP spec  Architectural style  Architectural basis for HTTP − Defined a posteriori
  • 5. Core REST Concepts  Identifiable Resources  Uniform interface  Stateless conversation  Resource representations  Hypermedia
  • 6. Identifiable Resources  Everything is a resource − Customer − Order − Catalog Item  Resources are accessed by URIs
  • 7. Uniform interface  Interact with Resource using single, fixed interface  GET /orders - fetch list of orders  GET /orders/1 - fetch order with id 1  POST /orders – create new order  PUT /orders/1 – update order with id 1  DELETE /orders/1 – delete order with id 1  GET /customers/1/order – all orders for customer with id 1
  • 8. Resource representations  More that one representation possible − text/html, image/gif, application/pdf  Desired representation set in Accept HTTP header − Or file extension  Delivered representation show in Content- Type  Access resources through representation  Prefer well-known media types
  • 9. Stateless conversation  Server does not maintain state − Don’t use the Session!  Client maintains state through links  Very scalable  Enforces loose coupling (no shared session knowledge)
  • 10. Hypermedia  Resources contain links  Client state transitions are made through these links  Links are provided by server  Example <oder ref=”/order/1”> <customer ref=”/customers/1”/> <lineItems> <lineItem item=”/catalog/item/125” qty=”10”/> <lineItem item=”/catalog/item/150” qty=”5”> </lineItems> </oder>
  • 12. RESTful application design  Identify resources − Design URIs  Select representations − Or create new ones  Identify method semantics  Select response codes
  • 13. Implement Restful API using Spring MVC
  • 14. Spring @MVC @Controller public class AccountController { @Autowired AccountService accountService; @RequestMapping("/details") public String details(@RequestParam("id")Long id, Model model) { Account account = accountService.findAccount(id); model.addAttribute(account); return "account/details"; } } account/details.jsp <h1>Account Details</h1> <p>Name : ${account.name}</p> <p>Balance : ${account.balance}</p> ../details?id=1
  • 15. RESTful support in Spring 3.0  Extends Spring @MVC to handle URL templates - @PathVariable  Leverages Spring OXM module to provide marshalling / unmarshalling (castor, xstream, jaxb etc)  @RequestBody – extract request body to method parameter  @ResponseBody – render return value to response body using converter – no views required
  • 16. REST controller @Controller public class AccountController { @RequestMapping(value="/accounts",method=RequestMethod.GET) @ResponseBody public AccountList getAllAcccount() { } @RequestMapping(value="/accounts/${id}",method=RequestMethod.GET) @ResponseBody public Account getAcccount(@PathVariable("id")Long id) { } @RequestMapping(value="/accounts/",method=RequestMethod.POST) @ResponseBody public Long createAcccount(@RequestBody Account account) { } @RequestMapping(value="/accounts/${id}",method=RequestMethod.PUT) @ResponseBody public Account updateAcccount(@PathVariable("id")Long id, @RequestBody Account account) { } @RequestMapping(value="/accounts/${id}",method=RequestMethod.DELETE) @ResponseBody public void deleteAcccount(@PathVariable("id")Long id) { } }
  • 17. web.xml <servlet> <servlet-name>rest-api</servlet-name> <servlet-class>org....web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>rest-api</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>
  • 18. rest-api-servlet-context.xml <bean id="marshaller" class="...oxm.xstream.XStreamMarshaller"> <property name="aliases"> <map> <entry key="category" value="...domain.Category"/> <entry key="catalogItem" value="...domain.CatalogItem"/> </map> </property> </bean>
  • 19. rest-api-servlet-context.xml <bean class="...mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <util:list> <bean class="...http.converter.xml.MarshallingHttpMessageConverter"> <constructor-arg ref="marshaller" /> </bean> <bean class="...http.converter.StringHttpMessageConverter" /> </util:list> </property> </bean>
  • 20. Invoke REST services  The new RestTemplate class provides client- side invocation of a RESTful web-service HTTP RestTemplate Method Method DELETE delete(String url, String... urlVariables) GET getForObject(String url, Class<t> responseType, String … urlVariables) HEAD headForHeaders(String url, String… urlVariables) OPTIONS optionsForAllow(String url, String… urlVariables) POST postForLocation(String url, Object request, String… urlVariables) PUT put(String url, Object request, String…urlVariables)
  • 21. REST template example AccountList accounts = restTemplate.getForObject("/accounts/",AccountList.class); Account account = restTemplate.getForObject("/accounts/${id}",Account.class ,"1"); restTemplate.postForLocation("/accounts/", account); restTemplate.put("/accounts/${id}",account,"1"); restTemplate.delete("/accounts/${id}", "1");
  • 22. Demo