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

REST 2015

REST 2015

Talk at W-JAX 2015 on what to know about REST in 2015

Silvia Schreier

November 03, 2015
Tweet

More Decks by Silvia Schreier

Other Decks in Programming

Transcript

  1. Why should I care? “Some architectural styles are often portrayed

    as “silver bullet” solutions for all forms of software. However, a good designer should select a style that matches the needs of the particular problem being solved.” — Roy Thomas Fielding
  2. Properties Separation of concerns Portability Scalability Independent evolution Loose coupling

    Visibility Reliability Improved network efficiency User-perceived performance Simplicity Efficient large-grain data transfer System extensibility
  3. How to REST in practice? derivative of by “A Nice

    Place To Sit” Richard Walker (CC BY 2.0)
  4. Typical pattern P O S T / l i s

    t with new element’s data in body 2 0 1 C r e a t e d with L o c a t i o n header as response
  5. Step 1: nominalization Accept  create acceptance Decline  create

    declination Apply for sth.  create application Send  trigger sending
  6. Step 2: match with HTTP verbs Create acceptance  P

    U T / t r i p s / 1 / a c c e p t a n c e Create declination  P U T / t r i p s / 2 / d e c l i n a t i o n with reason as body Create application  P O S T / t r i p s Trigger sending  P O S T / m e s s a g e / 1 / s e n d i n g
  7. How do I know what to do and where to

    find what? derivative of by “Future Bangkok MRT Map (printed)” Oran Viriyincy (CC BY 2.0)
  8. Browser features Hypermedia controls Content negotiation Status code handling, e.g.,

    redirects and auth Caching Handling unknown elements Code on demand Bookmarks
  9. Typical so called “REST clients” tripList = get("http://erp.innoq.com/trips"); lastTrip =

    get("http://erp.innoq.com/trips/" + tripList.last.id); response = post("http://erp.innoq.com/trips", tripData); newTrip = get("http://erp.innoq.com/trips/" + response.id);
  10. How to do better erpHome = get("http://erp.innoq.com"); trips = erpHome.followLink("trips");

    lastTrip = trips.links("trip").last.follow(); response = erpHome.extractLink("trips").post(tripData); newTrip = response.headers("location").get();
  11. Déjà vu: REST documentation URI Method Meaning h t t

    p : / / e r p . c o m / v 1 / t r i p s P O S T create new trip h t t p : / / e r p . c o m / v 1 / t r i p s / { i d } G E T get trip details h t t p : / / e r p / v 1 / t r i p s / { i d } / r e c e i p t s G E T get list of the trip's receipts ... ... ...
  12. Solution Documentation as additional resources Introduce documentation link relation Representations

    link to documentation Link header as an alternative Documentation links to link relations, media types and back to application
  13. Options for web UIs Component-based server frameworks e.g., Wicket, JSF

    Server-side MVC frameworks e.g., Spring MVC, Play, ASP.NET MVC Client-side MVC frameworks (SPA) & REST API e.g., AngularJS, Ember.js
  14. Is such an UI cool enough? derivative of by “#153

    Sun-glasses” Mikael Miettinen (CC BY 2.0)
  15. What is a modern web UI? Fast / immediate user

    feedback No full page reload Runs on different clients Works even with bad network connection Offline capability Accessibility
  16. As an architect I want more Maintainability Robustness Seperation of

    concerns No duplication of logic Accessible by search engines Security (we will talk about that later)
  17. ROCA RESTful server Business logic only on the server Best

    experience for all clients Understand the 3 piles of the web Use them as they were meant  Separation of concerns http://roca-style.org/
  18. Authentication Keep it as simple as possible: Basic Auth +

    SSL Cookie-based authentication TLS certificates Single sign-on
  19. SSO is not for free Complexity Many different options Token

    lifetime Redirect-based SSO causes problems with POST
  20. OAuth 2 Authorization framework not a protocol Only based on

    TLS Naive implementations are probably insecure Many open details Incompatible implementations
  21. Things you should care about : Cross-Site Request Forgery (CSRF)

    Cross-Origin Resource Sharing (CORS) Code injection Signatures and encryption ... Open Web Application Security Project checklist
  22. Summary REST: Which constraint induces which property? Documentation influcences your

    architecture Frontend architecture is a serious topic ROCA vs. SPA HTTP/2 is on its way Security in distributed systems is no free lunch
  23. More references (in German) (in German) Dissertation by Roy Thomas

    Fielding http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm REST APIs must be hypertext-driven http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven REST und HTTP http://rest-http.info/ Podcast zu „REST und HTTP“ https://www.innoq.com/de/podcast/022-rest-und-http/ Web architecture at innoQ https://www.innoq.com/de/topics/web/ Progressive Enhancement https://www.innoq.com/en/talks/2015/06/mediterraneajas-progressive-enhancement-talk/ Developing Modular JavaScript Components http://www.infoq.com/articles/modular-javascript http2 explained http://daniel.haxx.se/http2/ OAuth2 und OpenID Connect https://www.innoq.com/de/talks/2015/04/oauth2-openid-connect-jax2015/ OAuth 2.0 and the Road to Hell http://hueniverse.com/2012/07/26/oauth-2-0-and-the-road-to-hell/ OAuth 2 Simplified http://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified