Having Fun with the RestTemplate - GOTO...
Transcript of Having Fun with the RestTemplate - GOTO...
![Page 1: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/1.jpg)
Having Fun with the RestTemplate
Arjen PoutsmaSpringSource
VMware
woensdag 6 oktober 2010
![Page 2: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/2.jpg)
SpringSource Confidential. Do not distribute without express permission
Overview
• REST in 10 minutes
• RestTemplate
woensdag 6 oktober 2010
![Page 3: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/3.jpg)
REST in 10 minutes
woensdag 6 oktober 2010
![Page 4: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/4.jpg)
SpringSource Confidential. Do not distribute without express permission
REST
woensdag 6 oktober 2010
![Page 5: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/5.jpg)
SpringSource Confidential. Do not distribute without express permission
Identification
• Resources
• Typically nouns
• URIs
http://example.com/orders?year=2008http://example.com/customers/1234http://example.com/orders/2007/10/776654
woensdag 6 oktober 2010
![Page 6: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/6.jpg)
SpringSource Confidential. Do not distribute without express permission
Uniform Interface
woensdag 6 oktober 2010
![Page 7: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/7.jpg)
SpringSource Confidential. Do not distribute without express permission
Uniform Interface
woensdag 6 oktober 2010
![Page 8: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/8.jpg)
SpringSource Confidential. Do not distribute without express permission
Uniform Interface
GET Read
PUT Create or Update
POST Create
DELETE Delete
woensdag 6 oktober 2010
![Page 9: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/9.jpg)
SpringSource Confidential. Do not distribute without express permission
Uniform Interface
woensdag 6 oktober 2010
![Page 10: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/10.jpg)
SpringSource Confidential. Do not distribute without express permission
Uniform Interface
woensdag 6 oktober 2010
![Page 11: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/11.jpg)
SpringSource Confidential. Do not distribute without express permission
HATEOAS
• Hypermedia as the Engine of Application State
• No server-side state
• State transfer through links
woensdag 6 oktober 2010
![Page 12: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/12.jpg)
SpringSource Confidential. Do not distribute without express permission
GET /service/customers/1234 HTTP 1.1Host: www.example.comUser-Agent: XYZ 1.1Accept: text/html,application/xml;q=0.9,*/*;q=0.8If-Modified-Since: Thu, 18 Dec 2008 16:47:31 GMT If-None-Match: "600028c-59fb-474f6852c9dab"
HTTP/1.1 304 Not ModifiedDate: Fri, 19 Dec 2008 19:36:25 GMTLast-Modified: Thu, 18 Dec 2008 16:47:31 GMTEtag: "600028c-59fb-474f6852c9dab"Content-Length: 7160Content-Type: application/xml
<?xml version=‘1.0’ encoding=‘utf-8’ ?>
Self-Descriptive Messages
woensdag 6 oktober 2010
![Page 13: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/13.jpg)
SpringSource Confidential. Do not distribute without express permission
REST
woensdag 6 oktober 2010
![Page 14: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/14.jpg)
SpringSource Confidential. Do not distribute without express permission
REST
woensdag 6 oktober 2010
![Page 15: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/15.jpg)
SpringSource Confidential. Do not distribute without express permission
REST
woensdag 6 oktober 2010
![Page 16: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/16.jpg)
RestTemplate
woensdag 6 oktober 2010
![Page 17: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/17.jpg)
SpringSource Confidential. Do not distribute without express permission
RestTemplate
• Introduced in Spring 3.0
• RestTemplate as core client-side component
• Similar to other templates in Spring
• JdbcTemplate
• JmsTemplate
woensdag 6 oktober 2010
![Page 18: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/18.jpg)
SpringSource Confidential. Do not distribute without express permission
RestTemplate methods
• getForObject
• Performs GET and converts
• put
• Performs PUT
• postForLocation
• Performs POST, and retrieves Location header
• deletewoensdag 6 oktober 2010
![Page 19: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/19.jpg)
SpringSource Confidential. Do not distribute without express permission
RestTemplateString uri = "http://example.com/hotels/{id}"template = new RestTemplate();HotelList result = template.getForObject(uri, HotelList.class, "1");
Booking booking = // create booking objecturi = "http://example.com/hotels/{id}/bookings";Map<String, String> vars = Collections.singletonMap("id", "1");URI location = template.postForLocation(uri, booking, vars);
template.delete(location, );
template.execute(uri, HttpMethod.GET, myRequestCallback, myResponseCallback);
template.execute(uri, HttpMethod.GET, myRequestCallback, myResponseCallback);
woensdag 6 oktober 2010
![Page 20: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/20.jpg)
Demo’s
woensdag 6 oktober 2010
![Page 21: Having Fun with the RestTemplate - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/ArjenPoutsma_HavingFunW… · HTTP/1.1 304 Not Modified Date: Fri, 19 Dec 2008 19:36:25 GMT](https://reader034.fdocuments.us/reader034/viewer/2022050222/5f675a9d159d22375f153e5b/html5/thumbnails/21.jpg)
Q & A
woensdag 6 oktober 2010