Slide 1

Slide 1 text

Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data REST Data Meets Hypermedia By Greg Turnquist, Roy Clarkson, Oliver Gierke

Slide 2

Slide 2 text

2 Hypermedia is an adventure You only need a few tools But the results can be amazing

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

Oliver Gierke • Spring Data master • Spring HATEOAS • Jürgenized • Drums, music, … 5 @olivergierke

Slide 6

Slide 6 text

What is Spring Data REST? • Implements common patterns on top of repositories • Collection / Item resources • Association resources • Search resources • Supports • JPA, GemFire, Neo4j, MongoDB • Others are coming… 6

Slide 7

Slide 7 text

7

Slide 8

Slide 8 text

What is Spring Data REST? • Leverages hypermedia & internet standards • HAL (draft) • ALPS (draft) • URI Templates (RFC 6570) • text/uri-list mediatype (RFC 2483) • profile link relation (RFC 6906) 8 You aren’t building a “Spring Data REST” app, but instead a RESTful standards- based app.

Slide 9

Slide 9 text

9 HAL

Slide 10

Slide 10 text

10 Hypertext Application Language A lean hypermedia type application/hal+json HAL Adopting HAL will make your API explorable, and its documentation easily discoverable from within the API itself. — Mike Kelly, HAL spec lead

Slide 11

Slide 11 text

11 haltalk.herokuapp.com HAL

Slide 12

Slide 12 text

What is Spring Data REST? • What is ALPS? 12

Slide 13

Slide 13 text

Greg Turnquist • Spring Data REST • Spring Boot • Spring anything… • Getting started guides 13 Learning Spring Boot @gregturn

Slide 14

Slide 14 text

Architecture 14 GET /api Spring-a-Gram MVC SQL Spring Data Spring Mobile Spring Android Spring Hateoas Spring Framework

Slide 15

Slide 15 text

Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo: Spring-a-Gram

Slide 16

Slide 16 text

Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data REST Data Meets Hypermedia By Greg Turnquist, Roy Clarkson, Oliver Gierke

Slide 17

Slide 17 text

Hi, my name is Roy Clarkson 17 @royclarkson

Slide 18

Slide 18 text

18 Demo Spring-a-Gram Demo

Slide 19

Slide 19 text

Built with Spring components 19 Spring for Android Spring HATEOAS

Slide 20

Slide 20 text

What problem are we trying to solve? 20

Slide 21

Slide 21 text

Android REST client • Consistent programming model • Powerful • Extensible 21

Slide 22

Slide 22 text

Spring Framework vs Spring for Android • Core • RestTemplate 22 https://github.com/spring-projects/spring-android http://projects.spring.io/spring-android

Slide 23

Slide 23 text

HTTP Methods • DELETE - delete(...) • GET - getForObject(...) • HEAD - headForHeaders(...) • OPTIONS - optionsForAllow(...) • POST - postForLocation(...) • PUT - put(...) • any HTTP operation - exchange(...) and execute(...) 23

Slide 24

Slide 24 text

RestTemplate Example 24 RestTemplate restTemplate = new RestTemplate();! String url = "http://example.com/hotels/{hotel}/bookings/{booking}";! String result = restTemplate.getForObject(url, String.class, "42", “21”);!

Slide 25

Slide 25 text

HTTP Message Converters • MappingJackson2HttpMessageConverter - object to JSON marshaling supported via the Jackson JSON Processor • GsonHttpMessageConverter - object to JSON marshaling supported via Google Gson • SimpleXmlHttpMessageConverter - object to XML marshaling supported via the Simple XML Serializer 25

Slide 26

Slide 26 text

Spring for Android 2.0.0.M1 • Generics • OkHttp • API parity • Dependency updates • Bug fixes • Based on Spring Framework 3.2.x 26

Slide 27

Slide 27 text

Supported Android Versions 27 https://developer.android.com/about/dashboards/index.html

Slide 28

Slide 28 text

HTTP Clients • Native • Standard J2SE facilities (UrlConnection) • HttpComponents HttpClient 4.1 • Third Party • OkHttp • HttpComponents HttpClient 4.3 28

Slide 29

Slide 29 text

Generics 29 ParameterizedTypeReference> typeRef =! new ParameterizedTypeReference>() { };! ! ResponseEntity> responseEntity = ! restTemplate.exchange(url, HttpMethod.GET, requestEntity, typeRef);

Slide 30

Slide 30 text

Project Roadmap • HttpComponents 4.3 • AsyncRestTemplate • Improved Spring Social integration • Improved Spring HATEOAS integration • WebSocket • Differential Sync 30

Slide 31

Slide 31 text

Getting Started Guides at http://spring.io/guides • Consuming a RESTful Web Service with Spring for Android • Consuming XML from a RESTful Web Service with Spring for Android • Building Android Projects with Gradle • Building Android Projects with Maven • Installing the Android Development Environment 31

Slide 32

Slide 32 text

Let’s look at some code! 32

Slide 33

Slide 33 text

33 github.com/spring-projects/spring-data-rest github.com/spring-projects/spring-android github.com/SpringOne2GX-2014/spring-a-gram github.com/SpringOne2GX-2014/spring-a-gram-android Want to see more? Questions?