SlideShare une entreprise Scribd logo
1  sur  52
Télécharger pour lire hors ligne
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




               RESTful Web Apps
               Facts vs Fiction

               Subbu Allamaraju
               Yahoo! Inc || http://subbu.org




Subbu Allamaraju - RESTful Web Applications
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                About
   Tech Yahoo!
          Developing standards, patterns and
           practices for HTTP web APIs
   Past
          Developer – web services and Java
          Standards contributor at BEA
          Wrote books on JEE web tier (so long ago)
   Current Passion
          HTTP and REST
Subbu Allamaraju – RESTful Web Apps                              Slide 2
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Disclaimer


   All the opinions I express here are mine
   and do not necessarily represent those
       of my present or past employers.




Subbu Allamaraju – RESTful Web Apps                              3
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                A Confession
   Not a web developer
   Not directly interested in the internals
    of web frameworks
   Only interested in the visible aspects of
    web apps




Subbu Allamaraju – RESTful Web Apps                              4
Colorado Software Summit: October 19 – 24, 2008    © Copyright 2008, Yahoo! Inc.




                Agenda


                                REST – The Architecture




                  About RESTfulness of Web Apps



Subbu Allamaraju – RESTful Web Apps                               5
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Some History
 1945 - Vannevar Bush
   arbitrary linking between pieces of information
 1965 – Ted Nelson (Xanadu fame)
   hypertext and hypermedia
 1990s – Tim Berners-Lee, Roy Fielding et. al.
   WWW, HTML, HTTP and URI
   HTTP 1.1 - RFC 2616
   URI - RFC 2396 (superceded by 3986)
 2000 – Roy Fielding
   Representational State Transfer


Subbu Allamaraju – RESTful Web Apps                              6
Colorado Software Summit: October 19 – 24, 2008                © Copyright 2008, Yahoo! Inc.




                Two Sides
       RPC                                        HTTP, URI, WWW

                                                  REST      Web frameworks

                          SOAP                               MVC
                        “Pragmatic                                     This
                          WS-*
                          REST”                                       session
                                                              Web 2.0
                                         REST                + REST URIs
                                                             (?)

                               Machine Facing Human Facing
Subbu Allamaraju – RESTful Web Apps                                           7
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




       WEB IS MOSTLY RESTFUL




Subbu Allamaraju – RESTful Web Apps                              8
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Being RESTful
 Resources
   Named via URIs Uniquely identify resources
   Have representations Mostly one/resource
     Reflect the state of the app
                                     HATEOAS
     Contain contextual links
 Uniform interface Generic, Client-Server
   Idempotent, safe, cacheable …


Subbu Allamaraju – RESTful Web Apps                              9
Colorado Software Summit: October 19 – 24, 2008        © Copyright 2008, Yahoo! Inc.




                Resources and URIs
   Resources and URIs
          A blog post, an image, a catalog, a shopping cart



                                    Some personalized, but most are
                                     not
                                    Some depend on sessions, but
                                     most do not



Subbu Allamaraju – RESTful Web Apps                                   10
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Cost of Personalized UI
                             http://my.example.org
                                       vs
                         http://www.example.org/subbu




Subbu Allamaraju – RESTful Web Apps                              11
Colorado Software Summit: October 19 – 24, 2008                   © Copyright 2008, Yahoo! Inc.




                Representations
   Rich of representations
          HTML, XML, JS, PDF, CSS, Flash, …

                                           Poor content negotiation
                                           Agent-driven negotiation +
                                             Poor negotiation headers
                                           Media types on responses
                                             ignored sometimes
                                             Constrained by HTML
                                           <a href=“mydoc.pdf”>Click</a>
                                             <a href=“myfeed.rss”>RSS Feed</a>
                                             <a href=“myfeed.atom”>Atom Feed</a>

Subbu Allamaraju – RESTful Web Apps                                              12
Colorado Software Summit: October 19 – 24, 2008       © Copyright 2008, Yahoo! Inc.




                Hypermedia and HATEOAS
   Rich Hypermedia
          Links and forms
          Contextual
   Auto-discoverable
          <link/>, microformats


                                    Except some new breed of Web
                                     Too Oh + REST goo


Subbu Allamaraju – RESTful Web Apps                                  13
Colorado Software Summit: October 19 – 24, 2008        © Copyright 2008, Yahoo! Inc.




                Uniform Interface
   Links and Forms
          GET and POST


                                    Still some misconceptions (e.g.
                                     POST is secure)
                                    Idempotency? Safety?
                                    GET URIs not always refreshable
                                    Still fighting the back button


Subbu Allamaraju – RESTful Web Apps                                   14
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Back Button
 Cache-Control: no-cache,no-store




 Redirect after POST
  a.k.a. PRG (POST/redirect/GET)




Subbu Allamaraju – RESTful Web Apps                              15
Colorado Software Summit: October 19 – 24, 2008           © Copyright 2008, Yahoo! Inc.




                Caching
   Web is read-most
   Cacheable
   Widely discussed

                                       Yet moderately ignored
                                       Cache busting
                                       Cache-ignorant frameworks
                                       Frameworks that prefer backend
                                        caching over HTTP caching

Subbu Allamaraju – RESTful Web Apps                                      16
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Caching Choices
   Back-end caching
          Non-uniform interface
          Need to explicitly program to it
   HTTP caching
          Uniform interface
          Pluggable




Subbu Allamaraju – RESTful Web Apps                              17
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Ajax Apps
   More opportunities to be RESTful
          Full support for the uniform interface
          Content negotiation, optimistic
           concurrency, caching
          HATEOAS
                 • Can loosen this constraint as long as the client
                   code is downloaded from the same server/app




Subbu Allamaraju – RESTful Web Apps                              18
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Cross-Domain Hacks
   script, iframe
   Tunnel requests over GET




Subbu Allamaraju – RESTful Web Apps                              19
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Web is Mostly RESTful
 Take advantage of the web arch



                        Breaking is EXPENSIVE
                        Breaking is CONFUSING
                        Breaking LOWERS expectations




Subbu Allamaraju – RESTful Web Apps                              20
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




       WEB FRAMEWORKS




Subbu Allamaraju – RESTful Web Apps                              21
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                State of Affairs

    Ease of programming



               Fragmentation and confusion


                          Innovation vs Correctness



Subbu Allamaraju – RESTful Web Apps                              22
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Circa 1997-
   There were servlets
   Basic plumbing, closely reflecting HTTP
    1.1
   A poor programming model
   But allowed a lot of frameworks to be
    built on top




Subbu Allamaraju – RESTful Web Apps                              23
Colorado Software Summit: October 19 – 24, 2008                     © Copyright 2008, Yahoo! Inc.




                Circa 2001-




                                                  Action Oriented


Subbu Allamaraju – RESTful Web Apps                                                24
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Circa 2004-
   Enter JSF & Co.
          A component based UI framework
   With known limitations
          Complex
          Slow
          Uses POST for almost everything
          And so on…
   Third-party patches

Subbu Allamaraju – RESTful Web Apps                              25
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Design Choice




Subbu Allamaraju – RESTful Web Apps                              26
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Where to keep this stuff?




Subbu Allamaraju – RESTful Web Apps                              27
Colorado Software Summit: October 19 – 24, 2008              © Copyright 2008, Yahoo! Inc.




                Consequence



                                                  We know.
                                                  So what?




Subbu Allamaraju – RESTful Web Apps                                         28
Colorado Software Summit: October 19 – 24, 2008                          © Copyright 2008, Yahoo! Inc.




                URI Overloading


                                                                     Resource
                        Client 1
                                                                      (URI)
                                                  Representation



                                                                     Resource
                        Client 2
                                                                      (URI)
                                                  Different
                                                  Representation
                                                  How was this chosen?



Subbu Allamaraju – RESTful Web Apps                                                     29
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                URI Overloading
   One URI – multiple representations
          No way to tell how a representation was
           chosen
          Can get wrong content from a cache
   HTTP does allow URI overloading
          Content negotiation aka “conneg”




Subbu Allamaraju – RESTful Web Apps                              30
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Content Negotiation

       Accept: application/atom+xml;q=1.0,text/html;q=0.1
       Accept-Charset: UTF-8
       Accept-Language: fr;q=1.0,en=0.8
       Accept-Encoding: gzip,deflate


            
Content-Type: application/atom+xml;charset=UTF-8
            
Content-Encoding: deflate
             Vary: Accept,Accept-Encoding




Subbu Allamaraju – RESTful Web Apps                              31
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Some Options
   Vary by cookie
          Not always recognized by caches
          Complex given the parameters in a cookie
                 • Domain, path, life time etc
   URLEncode
          Encode session ID into URIs
                 • ;jsessionid=d8sdasg7312
   Cache-control: no-cache,no-store

Subbu Allamaraju – RESTful Web Apps                              32
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                JSF Compromise

 <context-param>
    <param-name>
        javax.faces.STATE_SAVING_METHOD
    </param-name>
    <param-value>
        client
    </param-value>
 </context-param>




Subbu Allamaraju – RESTful Web Apps                              33
Colorado Software Summit: October 19 – 24, 2008                       © Copyright 2008, Yahoo! Inc.




                Implementation
                                                  Every request must be a POST



<form method=quot;POSTquot; action=quot;…quot;
   enctype=quot;…quot;>
   <input type=quot;hiddenquot; 
       name=quot;javax.faces.ViewState” 
       value=quot;H4s…zogsAAA==quot; />

   …
                                             State stuffed into forms as a
</form>
                                          hidden field




Subbu Allamaraju – RESTful Web Apps                                                  34
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Consequence



                        Breaks the uniform interface




Subbu Allamaraju – RESTful Web Apps                              35
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                JSF vs REST
   Caught between two extremes
          URIs no longer sufficient to identify a
           resource
          Interactions assume existence of session
           state – i.e. no longer stateless
          Uniform interface limited to POST
          Interactions not idempotent
          Representations not cacheable


Subbu Allamaraju – RESTful Web Apps                              36
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                JSF – Takeaway
   Focused heavily on a UI component
    model (AWT for the Web)
   Misinterpreted the web architecture
   Made some fundamental questionable
    choices
   You can patch, but can not fix
          15+ Ajax patches!



Subbu Allamaraju – RESTful Web Apps                              37
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




       WEB 2.0 MOTIVATED




Subbu Allamaraju – RESTful Web Apps                              38
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                GWT
   A cross-compilation based framework
          Write Java – generate JavaScript
          Mashes up client and server code into
           single source
          These layers communicate using GWT-RPC
   Typical RPC concern does not apply
          Coupling due to code generation
          Client downloaded from the same app


Subbu Allamaraju – RESTful Web Apps                              39
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                GWT-RPC


 Object result = someServ.doIt(new MyCallback());
 public class MyCallback extends AsyncCallback() 
 {
    public void onsuccess(Object result) 
    {
       ...
    }
 }




Subbu Allamaraju – RESTful Web Apps                              40
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                GWT-RPC over HTTP




Subbu Allamaraju – RESTful Web Apps                              41
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                GWT-RPC over HTTP
   Method calls POSTed to the server
          Transport object graphs
          Uses HTTP like a transport layer
   Non uniform interface




Subbu Allamaraju – RESTful Web Apps                              42
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                GWT – Request Builder


 String url = quot;...quot;;
 RequestBuilder builder =
                new RequestBuilder(RequestBuilder.GET, 
                                   URL.encode(url));
 builder.sendRequest(data, callback);




Subbu Allamaraju – RESTful Web Apps                              43
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                RequestBuilder over HTTP
   More control over HTTP requests
   Supports GET and POST
   Allows so-called RESTful layers
          GWT-REST
          GWT-Restlet




Subbu Allamaraju – RESTful Web Apps                              44
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                GWT Takeway
   Focused heavily on ease of use
          Javascript agnostic
   Modeled after RPC
          Breaks uniform interface
          Backend caching over HTTP caching
   Fixable




Subbu Allamaraju – RESTful Web Apps                              45
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Fixing GWT?

 Object result = someServ.doGet(new MyCallback());

 Object result = someServ.doPost(new MyCallback());

 Object result = someServ.doPut(new MyCallback());

 Object result = someServ.doDelete(new MyCallback());

 Object result = someServ.doHead(new MyCallback());




Subbu Allamaraju – RESTful Web Apps                              46
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                SOFEA
   Central premise – SOA
          Business logic as reusable services
                 • Change less often
          Presentation app calling those services
                 • Change more often
          Separation of concerns and Loose coupling
   Misinterprets HATEOAS



Subbu Allamaraju – RESTful Web Apps                              47
Colorado Software Summit: October 19 – 24, 2008                     © Copyright 2008, Yahoo! Inc.




                HATEOAS vs SOFEA
                                                                 Download server
                                                  App download




                    App flow
                                                      Data
                                                  interchange



                                                                 Business logic
                                                                 server
             App container




Subbu Allamaraju – RESTful Web Apps                                                48
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Appcelerator
   A SOFEA style framework with RoR like
    usability
          Attend Matt Riable’s session on “Building
           Rich Internet Applications with
           Appcelerator”
   SOAP/HTTP style
          Message passing
          POST to a single URI


Subbu Allamaraju – RESTful Web Apps                              49
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                XML over POST




Subbu Allamaraju – RESTful Web Apps                              50
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Interesting … but
   Loosens HATEOAS
          Hypermedia to Code + Data
   Introduces a different kind of coupling
          Clients deal with POX and not links
          Breaks URI opacity
   Examples
          Appcelerator – SOAP like
          http://www.applebox.com.au - uses SOAP/POST
          http://www.contactoffice.com - uses XML/POST


Subbu Allamaraju – RESTful Web Apps                              51
Colorado Software Summit: October 19 – 24, 2008   © Copyright 2008, Yahoo! Inc.




                Thanks
   Don’t fight the architecture
          Innovate, enhance
          Don’t break
          Or break judiciously




Subbu Allamaraju – RESTful Web Apps                              52

Contenu connexe

En vedette

Stefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To RestStefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To Rest
deimos
 

En vedette (13)

Pragmatic Rest
Pragmatic RestPragmatic Rest
Pragmatic Rest
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
WP REST API: Actionable.co
WP REST API: Actionable.coWP REST API: Actionable.co
WP REST API: Actionable.co
 
The Rest Architectural Style
The Rest Architectural StyleThe Rest Architectural Style
The Rest Architectural Style
 
Teach a Dog to REST
Teach a Dog to RESTTeach a Dog to REST
Teach a Dog to REST
 
REST 101: An Overview To Representational State Transfer.
REST 101: An Overview To Representational State Transfer.REST 101: An Overview To Representational State Transfer.
REST 101: An Overview To Representational State Transfer.
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
REST to RESTful Web Service
REST to RESTful Web ServiceREST to RESTful Web Service
REST to RESTful Web Service
 
Stefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To RestStefan Tilkov Pragmatic Intro To Rest
Stefan Tilkov Pragmatic Intro To Rest
 
ReST (Representational State Transfer) Explained
ReST (Representational State Transfer) ExplainedReST (Representational State Transfer) Explained
ReST (Representational State Transfer) Explained
 
Design Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIsDesign Beautiful REST + JSON APIs
Design Beautiful REST + JSON APIs
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
HATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API StyleHATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API Style
 

Similaire à RESTful Web Apps - Facts vs Fiction

Web Publishing: An Overview of Tools and Service
Web Publishing: An Overview of Tools and ServiceWeb Publishing: An Overview of Tools and Service
Web Publishing: An Overview of Tools and Service
kilmeny21
 
Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
elliando dias
 
InsideRIA Outlook for 2009
InsideRIA Outlook for 2009InsideRIA Outlook for 2009
InsideRIA Outlook for 2009
AndreCharland
 
Netapp Michael Galpin
Netapp Michael GalpinNetapp Michael Galpin
Netapp Michael Galpin
rajivmordani
 
Frank Mantek Google G Data
Frank Mantek Google G DataFrank Mantek Google G Data
Frank Mantek Google G Data
deimos
 

Similaire à RESTful Web Apps - Facts vs Fiction (20)

Yahoo Developer Network overview
Yahoo Developer Network overviewYahoo Developer Network overview
Yahoo Developer Network overview
 
Search Engines and Flash: Secrets, Tricks, and Black Magic
Search Engines and Flash: Secrets, Tricks, and Black MagicSearch Engines and Flash: Secrets, Tricks, and Black Magic
Search Engines and Flash: Secrets, Tricks, and Black Magic
 
Beyond web services: supporting mashup artists at Yahoo!
Beyond web services: supporting mashup artists at Yahoo!Beyond web services: supporting mashup artists at Yahoo!
Beyond web services: supporting mashup artists at Yahoo!
 
Apache Solr Changes the Way You Build Sites
Apache Solr Changes the Way You Build SitesApache Solr Changes the Way You Build Sites
Apache Solr Changes the Way You Build Sites
 
Have Some Rest Building Web2.0 Apps And Services
Have Some Rest   Building Web2.0 Apps And ServicesHave Some Rest   Building Web2.0 Apps And Services
Have Some Rest Building Web2.0 Apps And Services
 
REST Introduction (PHP London)
REST Introduction (PHP London)REST Introduction (PHP London)
REST Introduction (PHP London)
 
Enterprise Mashups With Soa
Enterprise Mashups With SoaEnterprise Mashups With Soa
Enterprise Mashups With Soa
 
Prototyping Adobe AIR Applications with Fireworks CS4
Prototyping Adobe AIR Applications with Fireworks CS4Prototyping Adobe AIR Applications with Fireworks CS4
Prototyping Adobe AIR Applications with Fireworks CS4
 
Web Publishing: An Overview of Tools and Service
Web Publishing: An Overview of Tools and ServiceWeb Publishing: An Overview of Tools and Service
Web Publishing: An Overview of Tools and Service
 
Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
 
Rest Vs Soap Yawn2289
Rest Vs Soap Yawn2289Rest Vs Soap Yawn2289
Rest Vs Soap Yawn2289
 
Web Performance 101
Web Performance 101Web Performance 101
Web Performance 101
 
OneSpring: 5 Myths of Rich Internet Applications
OneSpring:  5 Myths of Rich Internet ApplicationsOneSpring:  5 Myths of Rich Internet Applications
OneSpring: 5 Myths of Rich Internet Applications
 
InsideRIA Outlook for 2009
InsideRIA Outlook for 2009InsideRIA Outlook for 2009
InsideRIA Outlook for 2009
 
Netapp Michael Galpin
Netapp Michael GalpinNetapp Michael Galpin
Netapp Michael Galpin
 
Frank Mantek Google G Data
Frank Mantek Google G DataFrank Mantek Google G Data
Frank Mantek Google G Data
 
Faster web pages
Faster web pagesFaster web pages
Faster web pages
 
Web 2.0 Impact on the Enterprise
Web 2.0 Impact on the EnterpriseWeb 2.0 Impact on the Enterprise
Web 2.0 Impact on the Enterprise
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawn
 
Best And Worst Practices Building Ria with Adobe and Microsoft
Best And Worst Practices Building Ria with Adobe and MicrosoftBest And Worst Practices Building Ria with Adobe and Microsoft
Best And Worst Practices Building Ria with Adobe and Microsoft
 

Plus de Subbu Allamaraju

Making Things Work Together
Making Things Work TogetherMaking Things Work Together
Making Things Work Together
Subbu Allamaraju
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale
Subbu Allamaraju
 

Plus de Subbu Allamaraju (16)

Five Rules
Five RulesFive Rules
Five Rules
 
Leading a Transformation
Leading a TransformationLeading a Transformation
Leading a Transformation
 
Taming the Rate of Change
Taming the Rate of ChangeTaming the Rate of Change
Taming the Rate of Change
 
What Worked for Netflix May Not Work for You (OSCON-2018)
What Worked for Netflix May Not Work for You (OSCON-2018)What Worked for Netflix May Not Work for You (OSCON-2018)
What Worked for Netflix May Not Work for You (OSCON-2018)
 
Are We Ready for Serverless
Are We Ready for ServerlessAre We Ready for Serverless
Are We Ready for Serverless
 
How to Sell Serverless to Your Colleagues
How to Sell Serverless to Your ColleaguesHow to Sell Serverless to Your Colleagues
How to Sell Serverless to Your Colleagues
 
Turning Containers into Cattle
Turning Containers into CattleTurning Containers into Cattle
Turning Containers into Cattle
 
Keystone at the Center of Our Universe
Keystone at the Center of Our UniverseKeystone at the Center of Our Universe
Keystone at the Center of Our Universe
 
Journey and future of OpenStack eBay and PayPal
Journey and future of OpenStack eBay and PayPalJourney and future of OpenStack eBay and PayPal
Journey and future of OpenStack eBay and PayPal
 
Engineering operations
Engineering operationsEngineering operations
Engineering operations
 
Open stack@ebay
Open stack@ebayOpen stack@ebay
Open stack@ebay
 
Making Things Work Together
Making Things Work TogetherMaking Things Work Together
Making Things Work Together
 
ql.io at NodePDX
ql.io at NodePDXql.io at NodePDX
ql.io at NodePDX
 
ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale ql.io: Consuming HTTP at Scale
ql.io: Consuming HTTP at Scale
 
Measuring REST
Measuring RESTMeasuring REST
Measuring REST
 
REST: Theory vs Practice
REST: Theory vs PracticeREST: Theory vs Practice
REST: Theory vs Practice
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

RESTful Web Apps - Facts vs Fiction

  • 1. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. RESTful Web Apps Facts vs Fiction Subbu Allamaraju Yahoo! Inc || http://subbu.org Subbu Allamaraju - RESTful Web Applications
  • 2. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. About   Tech Yahoo!  Developing standards, patterns and practices for HTTP web APIs   Past  Developer – web services and Java  Standards contributor at BEA  Wrote books on JEE web tier (so long ago)   Current Passion  HTTP and REST Subbu Allamaraju – RESTful Web Apps Slide 2
  • 3. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Disclaimer All the opinions I express here are mine and do not necessarily represent those of my present or past employers. Subbu Allamaraju – RESTful Web Apps 3
  • 4. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. A Confession   Not a web developer   Not directly interested in the internals of web frameworks   Only interested in the visible aspects of web apps Subbu Allamaraju – RESTful Web Apps 4
  • 5. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Agenda REST – The Architecture About RESTfulness of Web Apps Subbu Allamaraju – RESTful Web Apps 5
  • 6. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Some History 1945 - Vannevar Bush arbitrary linking between pieces of information 1965 – Ted Nelson (Xanadu fame) hypertext and hypermedia 1990s – Tim Berners-Lee, Roy Fielding et. al. WWW, HTML, HTTP and URI HTTP 1.1 - RFC 2616 URI - RFC 2396 (superceded by 3986) 2000 – Roy Fielding Representational State Transfer Subbu Allamaraju – RESTful Web Apps 6
  • 7. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Two Sides RPC HTTP, URI, WWW REST Web frameworks SOAP MVC “Pragmatic This WS-* REST” session Web 2.0 REST + REST URIs (?) Machine Facing Human Facing Subbu Allamaraju – RESTful Web Apps 7
  • 8. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. WEB IS MOSTLY RESTFUL Subbu Allamaraju – RESTful Web Apps 8
  • 9. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Being RESTful Resources Named via URIs Uniquely identify resources Have representations Mostly one/resource Reflect the state of the app HATEOAS Contain contextual links Uniform interface Generic, Client-Server Idempotent, safe, cacheable … Subbu Allamaraju – RESTful Web Apps 9
  • 10. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Resources and URIs   Resources and URIs  A blog post, an image, a catalog, a shopping cart   Some personalized, but most are not   Some depend on sessions, but most do not Subbu Allamaraju – RESTful Web Apps 10
  • 11. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Cost of Personalized UI http://my.example.org vs http://www.example.org/subbu Subbu Allamaraju – RESTful Web Apps 11
  • 12. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Representations   Rich of representations  HTML, XML, JS, PDF, CSS, Flash, …   Poor content negotiation   Agent-driven negotiation + Poor negotiation headers   Media types on responses ignored sometimes Constrained by HTML   <a href=“mydoc.pdf”>Click</a> <a href=“myfeed.rss”>RSS Feed</a> <a href=“myfeed.atom”>Atom Feed</a> Subbu Allamaraju – RESTful Web Apps 12
  • 13. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Hypermedia and HATEOAS   Rich Hypermedia  Links and forms  Contextual   Auto-discoverable  <link/>, microformats   Except some new breed of Web Too Oh + REST goo Subbu Allamaraju – RESTful Web Apps 13
  • 14. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Uniform Interface   Links and Forms  GET and POST   Still some misconceptions (e.g. POST is secure)   Idempotency? Safety?   GET URIs not always refreshable   Still fighting the back button Subbu Allamaraju – RESTful Web Apps 14
  • 15. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Back Button Cache-Control: no-cache,no-store Redirect after POST a.k.a. PRG (POST/redirect/GET) Subbu Allamaraju – RESTful Web Apps 15
  • 16. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Caching   Web is read-most   Cacheable   Widely discussed   Yet moderately ignored   Cache busting   Cache-ignorant frameworks   Frameworks that prefer backend caching over HTTP caching Subbu Allamaraju – RESTful Web Apps 16
  • 17. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Caching Choices   Back-end caching  Non-uniform interface  Need to explicitly program to it   HTTP caching  Uniform interface  Pluggable Subbu Allamaraju – RESTful Web Apps 17
  • 18. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Ajax Apps   More opportunities to be RESTful  Full support for the uniform interface  Content negotiation, optimistic concurrency, caching  HATEOAS • Can loosen this constraint as long as the client code is downloaded from the same server/app Subbu Allamaraju – RESTful Web Apps 18
  • 19. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Cross-Domain Hacks   script, iframe   Tunnel requests over GET Subbu Allamaraju – RESTful Web Apps 19
  • 20. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Web is Mostly RESTful Take advantage of the web arch Breaking is EXPENSIVE Breaking is CONFUSING Breaking LOWERS expectations Subbu Allamaraju – RESTful Web Apps 20
  • 21. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. WEB FRAMEWORKS Subbu Allamaraju – RESTful Web Apps 21
  • 22. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. State of Affairs Ease of programming Fragmentation and confusion Innovation vs Correctness Subbu Allamaraju – RESTful Web Apps 22
  • 23. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Circa 1997-   There were servlets   Basic plumbing, closely reflecting HTTP 1.1   A poor programming model   But allowed a lot of frameworks to be built on top Subbu Allamaraju – RESTful Web Apps 23
  • 24. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Circa 2001- Action Oriented Subbu Allamaraju – RESTful Web Apps 24
  • 25. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Circa 2004-   Enter JSF & Co.  A component based UI framework   With known limitations  Complex  Slow  Uses POST for almost everything  And so on…   Third-party patches Subbu Allamaraju – RESTful Web Apps 25
  • 26. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Design Choice Subbu Allamaraju – RESTful Web Apps 26
  • 27. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Where to keep this stuff? Subbu Allamaraju – RESTful Web Apps 27
  • 28. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Consequence We know. So what? Subbu Allamaraju – RESTful Web Apps 28
  • 29. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. URI Overloading Resource Client 1 (URI) Representation Resource Client 2 (URI) Different Representation How was this chosen? Subbu Allamaraju – RESTful Web Apps 29
  • 30. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. URI Overloading   One URI – multiple representations  No way to tell how a representation was chosen  Can get wrong content from a cache   HTTP does allow URI overloading  Content negotiation aka “conneg” Subbu Allamaraju – RESTful Web Apps 30
  • 31. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Content Negotiation Accept: application/atom+xml;q=1.0,text/html;q=0.1 Accept-Charset: UTF-8 Accept-Language: fr;q=1.0,en=0.8 Accept-Encoding: gzip,deflate Content-Type: application/atom+xml;charset=UTF-8 Content-Encoding: deflate Vary: Accept,Accept-Encoding Subbu Allamaraju – RESTful Web Apps 31
  • 32. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Some Options   Vary by cookie  Not always recognized by caches  Complex given the parameters in a cookie • Domain, path, life time etc   URLEncode  Encode session ID into URIs • ;jsessionid=d8sdasg7312   Cache-control: no-cache,no-store Subbu Allamaraju – RESTful Web Apps 32
  • 33. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. JSF Compromise <context-param> <param-name> javax.faces.STATE_SAVING_METHOD </param-name> <param-value> client </param-value> </context-param> Subbu Allamaraju – RESTful Web Apps 33
  • 34. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Implementation Every request must be a POST <form method=quot;POSTquot; action=quot;…quot; enctype=quot;…quot;> <input type=quot;hiddenquot; name=quot;javax.faces.ViewState” value=quot;H4s…zogsAAA==quot; /> … State stuffed into forms as a </form> hidden field Subbu Allamaraju – RESTful Web Apps 34
  • 35. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Consequence Breaks the uniform interface Subbu Allamaraju – RESTful Web Apps 35
  • 36. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. JSF vs REST   Caught between two extremes  URIs no longer sufficient to identify a resource  Interactions assume existence of session state – i.e. no longer stateless  Uniform interface limited to POST  Interactions not idempotent  Representations not cacheable Subbu Allamaraju – RESTful Web Apps 36
  • 37. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. JSF – Takeaway   Focused heavily on a UI component model (AWT for the Web)   Misinterpreted the web architecture   Made some fundamental questionable choices   You can patch, but can not fix  15+ Ajax patches! Subbu Allamaraju – RESTful Web Apps 37
  • 38. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. WEB 2.0 MOTIVATED Subbu Allamaraju – RESTful Web Apps 38
  • 39. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. GWT   A cross-compilation based framework  Write Java – generate JavaScript  Mashes up client and server code into single source  These layers communicate using GWT-RPC   Typical RPC concern does not apply  Coupling due to code generation  Client downloaded from the same app Subbu Allamaraju – RESTful Web Apps 39
  • 40. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. GWT-RPC Object result = someServ.doIt(new MyCallback()); public class MyCallback extends AsyncCallback() { public void onsuccess(Object result) { ... } } Subbu Allamaraju – RESTful Web Apps 40
  • 41. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. GWT-RPC over HTTP Subbu Allamaraju – RESTful Web Apps 41
  • 42. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. GWT-RPC over HTTP   Method calls POSTed to the server  Transport object graphs  Uses HTTP like a transport layer   Non uniform interface Subbu Allamaraju – RESTful Web Apps 42
  • 43. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. GWT – Request Builder String url = quot;...quot;; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); builder.sendRequest(data, callback); Subbu Allamaraju – RESTful Web Apps 43
  • 44. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. RequestBuilder over HTTP   More control over HTTP requests   Supports GET and POST   Allows so-called RESTful layers  GWT-REST  GWT-Restlet Subbu Allamaraju – RESTful Web Apps 44
  • 45. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. GWT Takeway   Focused heavily on ease of use  Javascript agnostic   Modeled after RPC  Breaks uniform interface  Backend caching over HTTP caching   Fixable Subbu Allamaraju – RESTful Web Apps 45
  • 46. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Fixing GWT? Object result = someServ.doGet(new MyCallback()); Object result = someServ.doPost(new MyCallback()); Object result = someServ.doPut(new MyCallback()); Object result = someServ.doDelete(new MyCallback()); Object result = someServ.doHead(new MyCallback()); Subbu Allamaraju – RESTful Web Apps 46
  • 47. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. SOFEA   Central premise – SOA  Business logic as reusable services • Change less often  Presentation app calling those services • Change more often  Separation of concerns and Loose coupling   Misinterprets HATEOAS Subbu Allamaraju – RESTful Web Apps 47
  • 48. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. HATEOAS vs SOFEA Download server App download App flow Data interchange Business logic server App container Subbu Allamaraju – RESTful Web Apps 48
  • 49. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Appcelerator   A SOFEA style framework with RoR like usability  Attend Matt Riable’s session on “Building Rich Internet Applications with Appcelerator”   SOAP/HTTP style  Message passing  POST to a single URI Subbu Allamaraju – RESTful Web Apps 49
  • 50. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. XML over POST Subbu Allamaraju – RESTful Web Apps 50
  • 51. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Interesting … but   Loosens HATEOAS  Hypermedia to Code + Data   Introduces a different kind of coupling  Clients deal with POX and not links  Breaks URI opacity   Examples  Appcelerator – SOAP like  http://www.applebox.com.au - uses SOAP/POST  http://www.contactoffice.com - uses XML/POST Subbu Allamaraju – RESTful Web Apps 51
  • 52. Colorado Software Summit: October 19 – 24, 2008 © Copyright 2008, Yahoo! Inc. Thanks   Don’t fight the architecture  Innovate, enhance  Don’t break  Or break judiciously Subbu Allamaraju – RESTful Web Apps 52