Agile RESTful Web Development Michael Marth Michael Dürig v e l o p e r n i o r D e S e T e c h n o l o g y E v a n g e l i s t m i c h a e c o m l . m a r t h @ i g @ d a y . d a y . c o m a e l . d u e r m i c h
Jugs - Agenda REST in 15 minutes Meet Apache Sling demo & code
What is REST? B Technology A API D Architectural Style C SOAP’s arch enemy
REST: An Architectural Style One of many Architectural Styles Architectural principles of the web, defined a posteriori Defined through architectural g n constraints i d l e i F T . y o R Chief Scientist at Day Software
Styles and implementation examples REST style peer to peer style the web is the only relevant implementation of The Web Napster REST
REST ingredients Resources roughly the constraints s thesis Representations of resources from Roy’ Uniform interface Hypertext and links Stateless communication
Resources give all relevant things an ID http:/ / example.com/cars/models/320 don’ t have to be pretty Representations http:/ / example.com/cars/models/320.html http:/ / example.com/cars/models/320.json http:/ / example.com/cars/models/320.xml http:/ / example.com/cars/models/320.jsp
Uniform interface allows intermediaries to understand (caches, proxies) retrieve information, possibly GET cached PUT Update or create with known ID POST Create or append sub-resource DELETE Logically remove
Uniform interface allows intermediaries to understand (caches, proxies) check out the URL http:/ /www.youtube.com/watch? retrieve information, possibly GET v=oHg5SJYRHA0 cached PUT Update or create with known ID with method “WATCH” POST Create or append sub-resource DELETE Logically remove
Hypertext Link the “things” / the resources How? <link rel="some-concept" ref="/some-uri"> t n e i h l a c r n d c i o d d e e d d i o n c c d l r i e a n h t T O N Why?
A special browser for each web site? e.g. a Wikipedia browser that hardcodes http:/ / en.wikipedia.org/wiki/{concept} wikipedia amazon jugs.ch blogs nzz admin.ch search.ch infoq facebook gmail browser browser browser browser browser browser browser browser browser browser
A REST API must not define fixed resource names or hierarchies (an obvious coupling of client and server). Servers must have the freedom to control their own namespace.
If you need this it’s (probably) not REST
Stateless communication state is kept on the client, no server-side application state scalability requests are self-contained intermediaries client server GET / customer/1234/orders <link rel=” ...” ref=” /orders/123456789”></link> update software reboot POST /orders/123456789
RPC-style modelling vs. REST-style modelling /orders GET - list all orders m a n y o p e r PUT - unused a t i o n s POST - add new order DELETE - unused f e w i n s t a n c e s few operations /orders/{id} GET - get order details many instances PUT - update order OrderManagementService POST - add item DELETE - cancel order + getOrders() + submitOrder() /orders/{id}/submit + getOrderDetails() GET - unused + getOrdersForCustomers() PUT - unused <<interface>> + updateOrder() POST - submit order Resource + addOrderItem() DELETE - unused GET + cancelOrder() PUT /customers POST GET - list all customers DELETE CustomerManagementService PUT - unused POST - add new customer + getCustomers() DELETE - unused + addCustomer() + getCustomerDetails() /customers/{id} + updateCustomer() GET - get customer details + deleteCustomer() PUT - update customer POST - unused DELETE - delete customer /customers/{id}/orders GET - get all orders for customer PUT - unused POST - add order DELETE - cancel all customer orders
Why again? proven scalability proven to evolve proven cross-platform The Web Relevant for me?
REST for the Enterprise?
The Internet vs. The Enterprise One is a gigantic, uncontrollable anarchy of heterogeneous systems with varying quality that evolve independently and constantly get connected in new and unexpected ways. The other is a worldwide, publicly accessible series of interconnected computer networks that transmit data by packet switching using the standard Internet Protocol (IP). Stefan Tilkov - Pragmatic Introduction to REST
Jugs - Agenda REST in 15 minutes Meet Apache Sling demo & code
What’s Sling? “ Apache Sling is a RESTful web framework that uses a Java Content Repository to store and manage content.” just graduated in Apache incubator
What’s JCR ? “The API should be a standard, implementation independent, way to access content bi-directionally on a granular level within a ? content repository .”
Best of both worlds. sys tem file a base t d a h i e r - a r c h i e i n s t e e g r u r t c i t u r y t s read streams x t write a c c e s s locking query c o n t r o l multi- value versioning obser - un-structured full-text” sort “ vation order ory sit con p o e r tent
“Data First!” schemaless” aka “ JCR supports “ structure first ” as well. (but that’ s missing the point)
Known compliant Repositories * using third party connector * * Exo Microsoft Apache Jackrabbit Oracle XML DB OpenText Livelink ECMS Platform Sharepoint * Day CRX IBM FileNet P8 Xythos Repository Alfresco ECM Vignette V7 * * How many RDBMS vendors do you need? +hundreds of TCKs Interwoven registered IBM CM EMC Documentum Repository
Some known JCR Applications Fast BEA Portal Oracle Portal Enterprise Search Sun JBoss Portal Interface 21 OpenPortal Spring Framework Day Communique DAM magnolia WCMS Day Communique Apache Sling Collab Mindquarry Alfresco ECMS Collaboration Apache Tapestry QSLabs Apache Day Communiqué Compliance Cocoon WCMS IBM FileNet medic-2-medic WebSiteManager Artifactory Apache James mapofmedicine Maven Proxy Exo TYPO3 ECMS Platform GX WebManager v5.0 WCM InfoQ Hippo Liferay Nuxeo ECM Online Community CMS Enterprise Portal Jahia Sakai Framework E-learning Percussion QuickWCM Rhythmix Sourcemix WCMS Lutece Sourcemix Portal
Some known JCR Applications Fast BEA Portal Oracle Portal Enterprise Search Sun JBoss Portal Interface 21 OpenPortal Spring Framework Day Communique DAM magnolia WCMS Day Communique Apache Sling Collab Mindquarry Alfresco ECMS Collaboration Apache Tapestry QSLabs Apache Day Communiqué Compliance Cocoon WCMS IBM FileNet medic-2-medic WebSiteManager Artifactory Apache James mapofmedicine Maven Proxy Exo TYPO3 ECMS Platform GX WebManager v5.0 WCM InfoQ Hippo Liferay Nuxeo ECM Online Community CMS Enterprise Portal Jahia Sakai Framework E-learning Percussion QuickWCM Rhythmix Sourcemix WCMS Lutece Sourcemix Portal
JCR - Weatherforecast -5° -8° 2011 -12° 2010 2009
JCR 2.0 http://www.day.com/jsr283
A node is a resource GET /cars/audi/s4.txt User -agent Repository
A node is a resource POST /cars/audi/s48 write User -agent Y our content is your web Repository server
Web apps and Sling scripting /cars/audi/s4.details.html User -agent Repository
Web apps and Sling scripting /cars/audi/s4.details.html User -agent Repository 1 file needed Convention over configuration
Web apps and Sling scripting /cars/audi/s4.details.html User -agent Repository .esp .erb .scala
Web apps and Sling scripting URLs do matter! /cars/audi/s4.details.html vs. /product.jsp?id=/audi/s4 Passing in “ this” Addressing the “ (the resource) script”
Bonus
Sling is OSGi-based ) ” d e l b a n e “ t s u j t o n ( Apache Felix OSGi container extensible my my my scripts bundles bundles Sling Sling Sling JCR
Sling is OSGi-based ) ” d e l b a n e “ t s u j t o n ( Apache Felix OSGi container extensible my my my scripts bundles bundles modular Sling Sling Sling JCR hot deploy
SEE
DEMO
Recommend
More recommend