· 2018-01-24 · Total Body Circuit & Lower F0CUS SATURDAY Rest Rest Rest Rest Rest ŒNDAR.COM ...
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
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
about:eZ
about:eZ
Enterprise Open-source since 1999Creators of eZ Publish Platform
GlobalBusiness: http://ez.no | Community: http://share.ez.no
@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
about:me
about:me
eZ Publish Community since 2005Lead Community + Marketing at eZ
Content Management, Open-source, Mountaineering
@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
TO
DA
Y
REST
eZ Publish
REST in eZ Publish
DEMO
REST for UXTO
DA
Y
REST
5
REST?
h"p://en.wikipedia.org/wiki/Representa4onal_State_Transferh"p://www.infoq.com/ar4cles/rest-‐introduc4on
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
REST? (ctd)
h"p://en.wikipedia.org/wiki/Representa4onal_State_Transferh"p://www.infoq.com/ar4cles/rest-‐introduc4on
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
HTTP 1.1 Request - Anatomy
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
• ... or a custom verb: PATCH,COPY, ...
HTTP 1.1 Request - Anatomy
• HTTP verb / method : GET,POST,PUT,DELETE, TRACE,OPTIONS,HEAD, ...
• ... or a custom verb: PATCH,COPY, ...
• Set of headers
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
HTTP 1.1 Response - Anatomy
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
HTTP 1.1 Response - Anatomy• Status code (by @stevelosh)
• 1XX: hold on
• 2XX: here you go
• 3XX: go away
• 4XX: you f * * * * d up
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
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
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
eZ Publish
10
Standard Symfony2 App.
(=app)
Standard Symfony2 App.
(=app) +eZ Publish
bundles(PHP & REST APIs
+ Legacy)
vendor/ ezsystems/ ezpublish-kernel
Standard Symfony2 App.
(=app) +eZ Publish
bundles(PHP & REST APIs
+ Legacy)
vendor/ ezsystems/ ezpublish-kernel
+Full-blownBack-office
Standard Symfony2 App.
(=app) +eZ Publish
bundles(PHP & REST APIs
+ Legacy)
vendor/ ezsystems/ ezpublish-kernel
+Full-blownBack-office
THIS is eZ Publish 5
REST in eZ Publish
12
REST API in eZ Publish 4.x
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
REST API in eZ Publish 5.x
REST API in eZ Publish 5.x
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
A REST Layer on top of a world of Content
A REST Layer on top of a world of Content
A REST Layer on top of a world of Content \o/
DEMO
16
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
REST for UX
18
REST API for more than service-to-service: UX example
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.
REST API for more than service-to-service: UX example
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
REST API for more than service-to-service: UX example
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.
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
Wrap-up
24
TO
DA
Y
REST
eZ Publish
REST in eZ Publish
DEMO
REST for UXTO
DA
Y
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