Ole marius smestad - REST & PHP API : how to turn eZ Publish into a multi-channel machine

Post on 05-Dec-2014

93.035 views 1 download

description

 

Transcript of Ole marius smestad - REST & PHP API : how to turn eZ Publish into a multi-channel machine

eZ Winter Conference 2011, Nice

REST & PHP API

1mandag 31. januar 2011

Introduction

2

2mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Ole Marius Smestad

Lead engineer for eZ Publish

oms@ez.no

@dotten

3

About me

3mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Agenda

4

4mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Agenda

News and conceptual feature discussion

4

4mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Agenda

News and conceptual feature discussion

What has been done

4

4mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Agenda

News and conceptual feature discussion

What has been done

What is being delivered

4

4mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Agenda

News and conceptual feature discussion

What has been done

What is being delivered

How to put this work to use

4

4mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Agenda

News and conceptual feature discussion

What has been done

What is being delivered

How to put this work to use

A bit of code

4

4mandag 31. januar 2011

5

A retrospective

5mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

A retrospective

6

APIs

6mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

A retrospective

7

PHP

REST

eZ Publish API

7mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

8

Simple

8mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

8

Simple

Consistent

8mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

8

Simple

Consistent

Predictable

8mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

A clear relationship

9

9mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

A clear relationship

9

Objects Tasks

Concepts

9mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

10

Simple

Consistent

Predictable

10mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

PHP APIs should be

10

Simple

Consistent

Predictable

A stable point of reference

10mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

A retrospective

11

PHP

REST

eZ Publish API

11mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

A retrospective

12

REST

12mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

A retrospective

12

RESTREST

12mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad 13

( )13mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

REST as a core feature

14

14mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

HTTP is the carrier

15

15mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

dedicated front-controller

16

16mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

back to the mothership

17

17mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

18

REST setup

REST

FC

eZPREST  reqest

eZ  Publishweb-­‐request

18mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

19

REST setup

eZPREST

FC

19mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

20

mapping content into resources

20mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

21

Makes data availableMakes data available

21mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

21

Makes data reusableMakes data reusable

21mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

REST

22

content is liberated

22mandag 31. januar 2011

One point oh

23

23mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh

24

24mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh

24

Being released as a part of Matterhorn

24mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh

24

Being released as a part of Matterhorn

Focus on infrastructure and basics

24mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh

24

Being released as a part of Matterhorn

Focus on infrastructure and basics

Making content accessible (in useful ways)

24mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh

24

Being released as a part of Matterhorn

Focus on infrastructure and basics

Making content accessible (in useful ways)

Always adaptable

24mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh

Github repositories available today

25

25mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh – the fineprint

26

26mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh – the fineprint

Wonʼt support full CRUD in 1.0

26

26mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh – the fineprint

Wonʼt support full CRUD in 1.0

Waiting for additions to our PHP API to fully support this

26

26mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh – the fineprint

Wonʼt support full CRUD in 1.0

Waiting for additions to our PHP API to fully support this

Applies to built-in content resources

26

26mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh – the fineprint

Wonʼt support full CRUD in 1.0

Waiting for additions to our PHP API to fully support this

Applies to built-in content resources

REST extensions will be able to provide all operations from day one

26

26mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

One point oh – the fineprint

Wonʼt support full CRUD in 1.0

Waiting for additions to our PHP API to fully support this

Applies to built-in content resources

REST extensions will be able to provide all operations from day one

26

26mandag 31. januar 2011

Key features

27

27mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

content resources

28

Key features

28mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Getting node data

GET /[api]/ezp/v1/content/⤦node/<ID> HTTP/1.1

29

29mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Getting node data

30

30mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Getting node data

classIdentifier

objectName

datePublished

dateModified

remoteID

objectRemoteID

nodeID

objectID

Full URL, etc.30

30mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Getting fields

GET /[api]/ezp/v1/content/⤦object/<objectId>/fields⤦

HTTP/1.1

31

31mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Getting fields

fields/<fieldname>

type (datatype string)

identifier (attribute identifier)

value (string representation of data)

id (object attribute numerical ID)

classattribute_id (class attribute numerical ID)

32

32mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Getting a specific field

GET /[api]/ezp/v1/content/⤦object/<objectId>/field/⤦<FieldIdentifier> HTTP/1.1

33

33mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Key features

Rendered view

34

34mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Key features

Systematic URLs

Response groups

Other resources available

child lists

sorting

35

35mandag 31. januar 2011

Extending the REST API

36

36mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

37

Extending REST

37mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix Provider VersionGET Host / / / / Call + params

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix Provider Version

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix

Provider Version

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix

Provider Version

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix

Provider

Version

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix

Provider

Version

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

URI pattern

38

Prefix

Provider

Version

Just a token to trigger your rewrite rule

ezpRestPrefixFilterInterface

38mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Remember, remember

39

ezpRestPrefixFilterInterface

39mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Prefix filter

40

Always knows

Current provider

Current parsed version value

40mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Versioned API

41

class ezpRestRouter extends ezcMvcRouter{ public function createRoutes() { // ezpRestApiProvider $routes = array( new ezcMvcRailsRoute( '/content/node/:nodeId/listAtom', 'ezpRestAtomController', 'collection' ), new ezcMvcRailsRoute( '/content/node/:nodeId/list', 'ezpRestContentController', 'list' ), new ezcMvcRailsRoute( '/content/node/:nodeId', 'ezpRestContentController', 'viewContent' ), new ezcMvcRailsRoute( '/content/node/:nodeId/fields', 'ezpRestContentController', 'viewFields' ), new ezcMvcRailsRoute( '/content/node/:nodeId/field/:fieldIdentifier', 'ezpRestContentController', 'viewField' ), new ezcMvcRailsRoute( '/content/object/:objectId', 'ezpRestContentController', 'viewContent' ), new ezcMvcRailsRoute( '/content/object/:objectId/fields', 'ezpRestContentController', 'viewFields' ), new ezcMvcRailsRoute( '/content/object/:objectId/field/:fieldIdentifier', 'ezpRestContentController', 'viewField' ),

new ezpRestVersionedRoute( new ezcMvcRailsRoute( '/foo', 'myController', 'myActionOne' ), 1 ), new ezpRestVersionedRoute( new ezcMvcRailsRoute( 'e/foo', 'myController2 or myControlerWhichExtendsmyController', 'myBetterAndScalingAction' ), 2 ), ); return ezcMvcRouter::prefix( '/api', $routes ); }}

41mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Versioned API

ezpRestVersionedRoute

42

42mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Versioned API

makes the notion version a part of the routing decision

43

Version

43mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Extending the interface

44

REST providers

44mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Extending the interface

ezpRestProviderInterface

45

45mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Extending the REST interface

Overview of hooks

46

46mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad 47

47mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Route setup 1

48

class ezpRestRouter extends ezcMvcRouter{ public function createRoutes() { // ezpRestApiProvider $routes = array( new ezcMvcRailsRoute( '/content/node/:nodeId/listAtom', 'ezpRestAtomController', 'collection' ), new ezcMvcRailsRoute( '/content/node/:nodeId/list', 'ezpRestContentController', 'list' ), new ezcMvcRailsRoute( '/content/node/:nodeId', 'ezpRestContentController', 'viewContent' ), new ezcMvcRailsRoute( '/content/node/:nodeId/fields', 'ezpRestContentController', 'viewFields' ), new ezcMvcRailsRoute( '/content/node/:nodeId/field/:fieldIdentifier', 'ezpRestContentController', 'viewField' ), new ezcMvcRailsRoute( '/content/object/:objectId', 'ezpRestContentController', 'viewContent' ), new ezcMvcRailsRoute( '/content/object/:objectId/fields', 'ezpRestContentController', 'viewFields' ), new ezcMvcRailsRoute( '/content/object/:objectId/field/:fieldIdentifier', 'ezpRestContentController', 'viewField' ),

new ezpRestVersionedRoute( new ezcMvcRailsRoute( '/foo', 'myController', 'myActionOne' ), 1 ), new ezpRestVersionedRoute( new ezcMvcRailsRoute( 'e/foo', 'myController2 or myControlerWhichExtendsmyController', 'myBetterAndScalingAction' ), 2 ), ); return ezcMvcRouter::prefix( '/api', $routes ); }}

48mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Route setup 2

49

class ezpRestRouter extends ezcMvcRouter{ public function createRoutes() { $providerRoutes = ezpRestProvider::getProvider( ezpRestPrefixFilterInterface::getApiProviderName() )->getRoutes();

$routes = array( new ezpMvcRailsRoute( '/fatal', 'ezpRestErrorController', 'show' ), new ezpMvcRailsRoute( '/http-basic-auth', 'ezpRestAuthController', 'basicAuth' ), new ezpMvcRailsRoute( '/login/oauth', 'ezpRestAuthController', 'oauthRequired' ), new ezpMvcRailsRoute( '/oauth/token', 'ezpRestOauthTokenController', 'handleRequest'),

// ezpRestVersionedRoute( $route, $version ) // $version == 1 should be the same as if the only the $route had been present new ezpRestVersionedRoute( new ezpMvcRailsRoute( '/foo', 'myController', 'myActionOne' ), 1 ), new ezpRestVersionedRoute( new ezpMvcRailsRoute( '/foo', 'myController', 'myActionOneBetter' ), 2 ),

);

return ezcMvcRouter::prefix( '/api', array_merge( $providerRoutes, $routes ) ); }}

49mandag 31. januar 2011

Protecting your resources

50

50mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

OAuth 2.0

51

Authentication

51mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Authentication

Basic auth

52

52mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Other security related options

Require HTTPS (a requirement of OAuth)

Decide which auth filter to use

53

53mandag 31. januar 2011

Summary

54

54mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

Gives access to existing content in a systematic way

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

Gives access to existing content in a systematic way

Output of content can be tweaked

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

Gives access to existing content in a systematic way

Output of content can be tweaked

Is extendible through eZ Market extensions

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

Gives access to existing content in a systematic way

Output of content can be tweaked

Is extendible through eZ Market extensions

API is versioned

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

Gives access to existing content in a systematic way

Output of content can be tweaked

Is extendible through eZ Market extensions

API is versioned

Control of BC

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Summary

Comes with the next release

Gives access to existing content in a systematic way

Output of content can be tweaked

Is extendible through eZ Market extensions

API is versioned

Control of BC

Control of already rolled out API clients

55

55mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Questions?

56

56mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

Possibility for more Q&A at the barcamp

57

57mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

The end

58

Thank you for listening

58mandag 31. januar 2011

27.01.2011Presenter: Ole Marius Smestad

The end

59

github.com/ezsystems/ezp_rest

59mandag 31. januar 2011