A REST Layer on Top of the World - IPC13 Munich
-
Upload
nicolas-pastorino -
Category
Technology
-
view
1.909 -
download
1
description
Transcript of A REST Layer on Top of the World - IPC13 Munich
![Page 1: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/1.jpg)
Nicolas Pastorino | eZ SystemsVP Community & Online Marketing@jeanvoye | [email protected]: Courtesy of Damien Pobel
A REST Layer on Top of The World
#REST #ezpublish #symfony #IPC13 #CMS #SOA #UX
![Page 2: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/2.jpg)
about:eZ
![Page 3: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/3.jpg)
about:eZ
Enterprise Open-source since 1999Creators of eZ Publish Platform
GlobalBusiness: http://ez.no | Community: http://share.ez.no
![Page 4: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/4.jpg)
@eZSystems
http://google.com/+ezsystems
http://linkedin.com/company/16738
https://github.com/ezsystems
about:eZ
Enterprise Open-source since 1999Creators of eZ Publish Platform
GlobalBusiness: http://ez.no | Community: http://share.ez.no
![Page 5: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/5.jpg)
about:me
![Page 6: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/6.jpg)
about:me
eZ Publish Community since 2005Lead Community + Marketing at eZ
Content Management, Open-source, Mountaineering
![Page 7: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/7.jpg)
@jeanvoye
http://bit.ly/nicolas-on-gplus
http://fr.linkedin.com/in/nicolaspastorino/
https://github.com/nfrp
about:me
eZ Publish Community since 2005Lead Community + Marketing at eZ
Content Management, Open-source, Mountaineering
![Page 8: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/8.jpg)
TO
DA
Y
![Page 9: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/9.jpg)
REST
eZ Publish
REST in eZ Publish
DEMO
REST for UXTO
DA
Y
![Page 10: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/10.jpg)
REST
5
![Page 11: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/11.jpg)
REST?
h"p://en.wikipedia.org/wiki/Representa4onal_State_Transferh"p://www.infoq.com/ar4cles/rest-‐introduc4on
![Page 12: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/12.jpg)
REST?Set of principles that define how Web standards, such as HTTP and URIs, are supposed to be used. Give every “thing” an ID
Link things together (“HATEOAS”) Use standard methods Resources with multiple representations Communicate statelessly
h"p://en.wikipedia.org/wiki/Representa4onal_State_Transferh"p://www.infoq.com/ar4cles/rest-‐introduc4on
![Page 13: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/13.jpg)
REST? (ctd)
h"p://en.wikipedia.org/wiki/Representa4onal_State_Transferh"p://www.infoq.com/ar4cles/rest-‐introduc4on
![Page 14: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/14.jpg)
REST? (ctd)Key goals of REST include: Scalability of component interactions Generality of interfaces Independent deployment of components Intermediary components to reduce latency, enforce security and encapsulate legacy systems
h"p://en.wikipedia.org/wiki/Representa4onal_State_Transferh"p://www.infoq.com/ar4cles/rest-‐introduc4on
![Page 15: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/15.jpg)
HTTP 1.1 Request - Anatomy
![Page 16: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/16.jpg)
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
![Page 17: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/17.jpg)
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
• ... or a custom verb: PATCH,COPY, ...
![Page 18: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/18.jpg)
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
• ... or a custom verb: PATCH,COPY, ...
• Set of headers
![Page 19: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/19.jpg)
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
• ... or a custom verb: PATCH,COPY, ...
• Set of headers
• A body in POST,PUT or custom verb requests
![Page 20: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/20.jpg)
HTTP 1.1 Response - Anatomy
![Page 21: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/21.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
![Page 22: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/22.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
![Page 23: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/23.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
![Page 24: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/24.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
![Page 25: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/25.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
• 4XX: you f * * * * d up
![Page 26: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/26.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
• 4XX: you f * * * * d up
• 5XX: I f * * * * d up
![Page 27: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/27.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
• 4XX: you f * * * * d up
• 5XX: I f * * * * d up
• Set of headers
![Page 28: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/28.jpg)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
• 4XX: you f * * * * d up
• 5XX: I f * * * * d up
• Set of headers
• A body depending on the response
![Page 29: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/29.jpg)
eZ Publish
10
![Page 30: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/30.jpg)
Standard Symfony2 App.
(=app)
![Page 31: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/31.jpg)
Standard Symfony2 App.
(=app) +eZ Publish
bundles(PHP & REST APIs
+ Legacy)
vendor/ ezsystems/ ezpublish-kernel
![Page 32: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/32.jpg)
Standard Symfony2 App.
(=app) +eZ Publish
bundles(PHP & REST APIs
+ Legacy)
vendor/ ezsystems/ ezpublish-kernel
+Full-blownBack-office
![Page 33: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/33.jpg)
Standard Symfony2 App.
(=app) +eZ Publish
bundles(PHP & REST APIs
+ Legacy)
vendor/ ezsystems/ ezpublish-kernel
+Full-blownBack-office
THIS is eZ Publish 5
![Page 34: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/34.jpg)
REST in eZ Publish
12
![Page 35: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/35.jpg)
REST API in eZ Publish 4.x
![Page 36: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/36.jpg)
REST API in eZ Publish 4.x
• eZ Publish 4.x has a REST API
• Prefix /ezp/api/v1/
• Read only
• Very limited scope / incomplete
![Page 37: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/37.jpg)
REST API in eZ Publish 5.x
![Page 38: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/38.jpg)
REST API in eZ Publish 5.x
![Page 39: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/39.jpg)
REST API in eZ Publish 5.x• Read / Write
• Prefix /ezp/api/v2/
• Allows to handle almost everything in the repository (Content, Location, Types, ...)
• Support Basic Auth and Session Auth
• XML or JSON support in input and output
• Hypermedia as the Engine of Application State (HATEOAS)• Specifications: http://j.mp/ezpublish-rest-spec
![Page 40: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/40.jpg)
A REST Layer on top of a world of Content
![Page 41: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/41.jpg)
A REST Layer on top of a world of Content
![Page 42: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/42.jpg)
A REST Layer on top of a world of Content \o/
![Page 43: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/43.jpg)
DEMO
16
![Page 44: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/44.jpg)
Demo Synopsis• Navigate to http://cp2013.9.loc/ then to http://cp2013.9.loc/Blog
• Add Blog post from http://cp2013.9.loc/ezdemo_site_admin/Blog (Content: http://phpconference.com/2013/en/sessions/rest-layer-top-world )
• REST: Request REST Root:
• chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/1
• Explain all parameters, then run.
• REST: Show children of Content root
• chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/2
• REST: Show Location/Content/ContentInfo for one child (“Blog”)
• chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/3
• chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/4 Edit Content, then reload.
• chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/5
• REST: Show children of one child (“Blog”)
• Show children: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/8
• Delete the previously created blog post: curl -u "admin:publish" -X DELETE http://cp2013.9.loc/api/ezp/v2/content/objects/<objectId>
• Refresh children list: Show children: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:projectEndpoint/8
• REST: Create an Image object
• Show ContentType (ContentClass) in back-office: http://cp2013.9.loc/ezdemo_site_admin/class/view/27
• Create image from command line
• $> cdipc13
• $> curl -u "admin:publish" -i -H "Accept: application/json" -H "Content-Type: application/vnd.ez.api.ContentCreate+json" -X POST -d @createimage.json http://cp2013.9.loc/api/ezp/v2/content/objects
• Publish object: curl -u "admin:publish" -X PUBLISH http://cp2013.9.loc/api/ezp/v2/content/objects/<object Id>/versions/1
• Show image in the back-office: http://cp2013.9.loc/ezdemo_site_admin/eZ-Systems-logo-created-with-the-REST-API
![Page 45: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/45.jpg)
REST for UX
18
![Page 46: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/46.jpg)
REST API for more than service-to-service: UX example
![Page 47: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/47.jpg)
REST API for more than service-to-service: UX example
• API REST as provider for ajax calls - data
• Initial page load (JS code, generating an interface) - then Ajax+REST for navigation, data retrieval,
• Total separation of functional UX and data retrieval + back-end business logic.
![Page 48: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/48.jpg)
REST API for more than service-to-service: UX example
![Page 49: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/49.jpg)
REST API for more than service-to-service: UX example• Tools
• JS lib, REST client: https://github.com/ezsystems/ez-js-rest-client
• Reproduction of the public PHP API: exposing services
• Relying on HATEOS, but simplifying usage of it
![Page 50: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/50.jpg)
REST API for more than service-to-service: UX example
![Page 51: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/51.jpg)
REST API for more than service-to-service: UX example• Why?
• Easy to discover the REST API structure from a client
• BC support: no URL hard-coding, painless client-side, all existing projects relying on the API need not be modified,
• Simplifies cache management (HTTP): easy to know exactly which resource is to be expired after a change in content repository.
![Page 52: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/52.jpg)
![Page 53: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/53.jpg)
![Page 54: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/54.jpg)
![Page 55: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/55.jpg)
![Page 56: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/56.jpg)
Demo Synopsis
• Navigate to http://cp2013.9.loc/summercamp/rest-test
• Open Console > Network > Filter with “XHR” only
• Reload page, and clear console
• Click on “Details” for “Blog”
• Inspect request in console:
• show”Accept” header value,
• show URL
• In “Preview” subtab: show response, focus on “Content.Section”
• --> Show next request (back to “Headers” subtab): Section
• show”Accept” header value,
• show URL
• In “Preview” subtab: show response, focus on “Section.name”
• --> Show next request (back to “Headers” subtab): Owner
![Page 57: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/57.jpg)
Wrap-up
24
![Page 58: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/58.jpg)
TO
DA
Y
![Page 59: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/59.jpg)
REST
eZ Publish
REST in eZ Publish
DEMO
REST for UXTO
DA
Y
![Page 60: A REST Layer on Top of the World - IPC13 Munich](https://reader033.fdocuments.us/reader033/viewer/2022042813/5484ea33b4af9f8c0d8b4d7b/html5/thumbnails/60.jpg)
eZ Publish Community http://share.ez.no
eZ Publish 5 Community Projecthttp://share.ez.no/download
https://github.com/ezsystems/ezpublish-community
eZ Systems & eZ Publish Platform Enterprise Editionhttp://ez.no
Slides available soon athttp://slideshare.net/jeanvoye
@jeanvoye
http://bit.ly/nicolas-on-gplus
http://fr.linkedin.com/in/nicolaspastorino/
https://github.com/nfrp