Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SpringOne2GX 2014: Spring Data REST - Data Meets Hypermedia

Greg Turnquist
September 10, 2014

SpringOne2GX 2014: Spring Data REST - Data Meets Hypermedia

See a demo of Spring Data REST where three different front ends interact with a single back end to snap pictures and upload them to Spring-a-Gram, a $1B acquisition in the making!

Greg Turnquist

September 10, 2014
Tweet

More Decks by Greg Turnquist

Other Decks in Programming

Transcript

  1. 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

    View Slide

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

    View Slide

  3. 3

    View Slide

  4. 4

    View Slide

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

    View Slide

  6. 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

    View Slide

  7. 7

    View Slide

  8. 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.

    View Slide

  9. 9
    HAL

    View Slide

  10. 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

    View Slide

  11. 11
    haltalk.herokuapp.com
    HAL

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. Hi, my name is Roy Clarkson
    17
    @royclarkson

    View Slide

  18. 18
    Demo
    Spring-a-Gram
    Demo

    View Slide

  19. Built with Spring components
    19
    Spring for
    Android
    Spring
    HATEOAS

    View Slide

  20. What problem are we trying to solve?
    20

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  24. 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”);!

    View Slide

  25. 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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  31. 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

    View Slide

  32. Let’s look at some code!
    32

    View Slide

  33. 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?

    View Slide