SlideShare a Scribd company logo
1 of 37
Building web services  with Zend Framework King Foo Jonas Mariën 13 July 2010, Vlissingen NL
This talk = beta remarks and suggestions are welcome
King Foo ,[object Object]
5 experienced PHP developers (4 Zend Certified Engineers, MySQL, Linux, scaling, and architecture experience
LAMP, but wandering off into different grounds at regular intervals Having fun with mobile stuff and web services for example ...
This talk ,[object Object]
About others talking to us So we're going to create web services: ,[object Object]
For others to consume
Question time Heard about / tried Zend Framework?
Zend Framework ,[object Object]
Sufficient documentation
MVC if you want
Nice server components
Zend Framework Download, unpack wget  http://framework.zend.com/releases/ZendFramework-1.10.6/ZendFramework-1.10.6.tar.gz tar zxvf ZendFramework-1.10.6.tar.gz cp -ar ZendFramework-1.10.6/library . cp -ar ZendFramework-1.10.6/bin . alias zf=bin/zf.sh  Create project, module, create controller with views zf create project . zf create module admin zf create controller index index-action-included=1 admin
Zend Framework You need one more thing to enable modules: resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.modules[] =  Plus, we want our own libraries, eventually: autoloaderNamespaces.kingfoo = "Kingfoo_"
Zend Framework . |-- application |  |-- Bootstrap.php |  |-- configs |  |  `-- application.ini |  |-- controllers |  |  |-- ErrorController.php |  |  `-- IndexController.php |  |-- models |  |-- modules |  |  `-- admin |  `-- views |  |-- helpers |  `-- scripts |-- bin |-- docs |  `-- README.txt |-- library |  `-- Zend |  |-- Acl |  |-- Acl.php |  .... |  |-- Wildfire |  `-- XmlRpc |-- public |  `-- index.php |-- tests |  |-- application |  |  |-- bootstrap.php |  |  `-- controllers |  |-- library |  |  `-- bootstrap.php |  `-- phpunit.xml . `-- admin |-- controllers |  `-- IndexController.php |-- models `-- views |-- filters |-- helpers `-- scripts . |-- application |  |-- Bootstrap.php |  |-- configs |  |  `-- application.ini |  |-- controllers |  |  |-- ErrorController.php |  |  `-- IndexController.php |  |-- models |  |-- modules |  |  `-- admin |  `-- views |  |-- helpers |  `-- scripts |-- bin |-- docs |  `-- README.txt |-- library |  `-- Zend |  |-- Acl |  |-- Acl.php |  .... |  |-- Wildfire |  `-- XmlRpc |-- public |  `-- index.php |-- tests |  |-- application |  |  |-- bootstrap.php |  |  `-- controllers |  |-- library |  |  `-- bootstrap.php |  `-- phpunit.xml
Zend Framework ,[object Object]
Add to /etc/hosts
Reload Apache
Question time Heard about / tried web services?
Web services From Wikipedia: Web services are typically application programming interfaces (API) or web APIs that are accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system hosting the requested services. Web services tend to fall into one of two camps: Big Web Services and RESTful Web Services.
Different kinds of WS ,[object Object]
XML-RPC
JSON-RPC
REST BTW, I don't want to talk about Zend_Amf
Exposing something class Kingfoo_Quote { public function __construct() { $array[0] = 'Chuck Norris counted to infinity - twice.'; $array[9] = 'Chuck Norris doesn’t wash his clothes, he disembowels them.'; $this->_quotes = $array; } /** * returns entire liste of quotes * @return array */ public function getList() { return $this->_quotes; } .... /** * returns a random single quote * @return string */ public function randomQuote() { $arr = $this->_quotes; shuffle($arr); return $arr[0]; } }
SOAP ,[object Object]
Big spec, even bigger with WS-*
RPC style, method oriented
Server and WSDL
SOAP 1.1 and SOAP 1.2 ,[object Object]
SOAP governed by a W3C working group
SOAP with ZF ,[object Object]
The real power: WSDL generation and reflection being used for discovery
Strategies for discovering more complex messages and responses are available
Docblock comments are very important here
SOAP with ZF if (isset($_GET['WSDL'])) { $autodiscover = new Zend_Soap_AutoDiscover(); $autodiscover->setClass('Kingfoo_Quote'); $autodiscover->setUri('http://presentation-zfws/SOAP.php'); $autodiscover->handle(); } else { $options = array('soap_version' => SOAP_1_2); $server = new Zend_Soap_Server('http://presentation-  zfws/SOAP.php?WSDL=1', $options); $server->setObject(new Kingfoo_Quote()); $server->handle(); }

More Related Content

What's hot

ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf Conference
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1
Shinya Ohyanagi
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
Felinx Lee
 

What's hot (20)

Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Psr-7
Psr-7Psr-7
Psr-7
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1Zend Framework Study@Tokyo vol1
Zend Framework Study@Tokyo vol1
 
Psr 7 symfony-day
Psr 7 symfony-dayPsr 7 symfony-day
Psr 7 symfony-day
 
Symfony without the framework
Symfony without the frameworkSymfony without the framework
Symfony without the framework
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016Demystifying Object-Oriented Programming - ZendCon 2016
Demystifying Object-Oriented Programming - ZendCon 2016
 
Rich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
 
Into the ZF2 Service Manager
Into the ZF2 Service ManagerInto the ZF2 Service Manager
Into the ZF2 Service Manager
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 

Similar to Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vlissingen)

Php Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc JaoPhp Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc Jao
jedt
 

Similar to Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vlissingen) (20)

Fatc
FatcFatc
Fatc
 
Php Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc JaoPhp Asp Net Interoperability Rc Jao
Php Asp Net Interoperability Rc Jao
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Best practices tekx
Best practices tekxBest practices tekx
Best practices tekx
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John Hardy
 
2007 Zend Con Mvc
2007 Zend Con Mvc2007 Zend Con Mvc
2007 Zend Con Mvc
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Native REST Web Services with Oracle 11g
Native REST Web Services with Oracle 11gNative REST Web Services with Oracle 11g
Native REST Web Services with Oracle 11g
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
Zend Framework Foundations
Zend Framework FoundationsZend Framework Foundations
Zend Framework Foundations
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 

Recently uploaded

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
 
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
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
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...
 

Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vlissingen)

  • 1. Building web services with Zend Framework King Foo Jonas Mariën 13 July 2010, Vlissingen NL
  • 2. This talk = beta remarks and suggestions are welcome
  • 3.
  • 4. 5 experienced PHP developers (4 Zend Certified Engineers, MySQL, Linux, scaling, and architecture experience
  • 5. LAMP, but wandering off into different grounds at regular intervals Having fun with mobile stuff and web services for example ...
  • 6.
  • 7.
  • 8. For others to consume
  • 9. Question time Heard about / tried Zend Framework?
  • 10.
  • 12. MVC if you want
  • 14. Zend Framework Download, unpack wget http://framework.zend.com/releases/ZendFramework-1.10.6/ZendFramework-1.10.6.tar.gz tar zxvf ZendFramework-1.10.6.tar.gz cp -ar ZendFramework-1.10.6/library . cp -ar ZendFramework-1.10.6/bin . alias zf=bin/zf.sh Create project, module, create controller with views zf create project . zf create module admin zf create controller index index-action-included=1 admin
  • 15. Zend Framework You need one more thing to enable modules: resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.modules[] = Plus, we want our own libraries, eventually: autoloaderNamespaces.kingfoo = "Kingfoo_"
  • 16. Zend Framework . |-- application | |-- Bootstrap.php | |-- configs | | `-- application.ini | |-- controllers | | |-- ErrorController.php | | `-- IndexController.php | |-- models | |-- modules | | `-- admin | `-- views | |-- helpers | `-- scripts |-- bin |-- docs | `-- README.txt |-- library | `-- Zend | |-- Acl | |-- Acl.php | .... | |-- Wildfire | `-- XmlRpc |-- public | `-- index.php |-- tests | |-- application | | |-- bootstrap.php | | `-- controllers | |-- library | | `-- bootstrap.php | `-- phpunit.xml . `-- admin |-- controllers | `-- IndexController.php |-- models `-- views |-- filters |-- helpers `-- scripts . |-- application | |-- Bootstrap.php | |-- configs | | `-- application.ini | |-- controllers | | |-- ErrorController.php | | `-- IndexController.php | |-- models | |-- modules | | `-- admin | `-- views | |-- helpers | `-- scripts |-- bin |-- docs | `-- README.txt |-- library | `-- Zend | |-- Acl | |-- Acl.php | .... | |-- Wildfire | `-- XmlRpc |-- public | `-- index.php |-- tests | |-- application | | |-- bootstrap.php | | `-- controllers | |-- library | | `-- bootstrap.php | `-- phpunit.xml
  • 17.
  • 20. Question time Heard about / tried web services?
  • 21. Web services From Wikipedia: Web services are typically application programming interfaces (API) or web APIs that are accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system hosting the requested services. Web services tend to fall into one of two camps: Big Web Services and RESTful Web Services.
  • 22.
  • 25. REST BTW, I don't want to talk about Zend_Amf
  • 26. Exposing something class Kingfoo_Quote { public function __construct() { $array[0] = 'Chuck Norris counted to infinity - twice.'; $array[9] = 'Chuck Norris doesn’t wash his clothes, he disembowels them.'; $this->_quotes = $array; } /** * returns entire liste of quotes * @return array */ public function getList() { return $this->_quotes; } .... /** * returns a random single quote * @return string */ public function randomQuote() { $arr = $this->_quotes; shuffle($arr); return $arr[0]; } }
  • 27.
  • 28. Big spec, even bigger with WS-*
  • 29. RPC style, method oriented
  • 31.
  • 32. SOAP governed by a W3C working group
  • 33.
  • 34. The real power: WSDL generation and reflection being used for discovery
  • 35. Strategies for discovering more complex messages and responses are available
  • 36. Docblock comments are very important here
  • 37. SOAP with ZF if (isset($_GET['WSDL'])) { $autodiscover = new Zend_Soap_AutoDiscover(); $autodiscover->setClass('Kingfoo_Quote'); $autodiscover->setUri('http://presentation-zfws/SOAP.php'); $autodiscover->handle(); } else { $options = array('soap_version' => SOAP_1_2); $server = new Zend_Soap_Server('http://presentation- zfws/SOAP.php?WSDL=1', $options); $server->setObject(new Kingfoo_Quote()); $server->handle(); }
  • 38.
  • 41.
  • 43. Limited set of datatypes, nothing like WSDL
  • 44.
  • 45. That container should contain a single methodName tag
  • 46. The method name should be a string only containin a-z,A-Z,0-9 and any of these characters: _ . : /
  • 47. It is up to the server how to interprete this methodName
  • 48. Parameters for the methodName being called are contained in a params tag
  • 49. Inside the params tag, one or more param tags are listed
  • 50. Each param tag looks like this: <param><value>...</value></param>
  • 51. XML-RPC REQUEST: <?xml version=&quot;1.0&quot;?> <methodCall> <methodName>zfwsdemo.getQuote</methodName> <params> <param> <value><int>2</int></value> </param> </params> </methodCall> </code> RESPONSE <code> <?xml version=&quot;1.0&quot;?> <methodResponse> <params> <param> <value>... Chuck Norris ...</value> </param> </params> </methodResponse> </code>
  • 52.
  • 53.
  • 54. system.* (listMethods, methodSignature, methodHelp, multicall ...)
  • 55. XML-RPC with ZF SERVER $server = new Zend_XmlRpc_Server(); $server->setClass('Kingfoo_Quote','zfwsdemo'); echo $server->handle(); CLIENT $client = new Zend_XmlRpc_Client('http://presentation-zfws/XMLRPC.php'); //get list of methods $result = $client->call('system.listMethods'); //get a random quote $result = $client->call('zfwsdemo.randomQuote');
  • 56.
  • 57. TCP/IP sockets are allowed too (not only HTTP)
  • 58. Request, response, error object, batches
  • 59. Client and server are peers, sending each other notifications
  • 60.
  • 62. JSON-RPC with ZF SERVER $server = new Zend_Json_Server(); $server->setClass('Kingfoo_Quote'); $server->handle(); CLIENT $request = new stdClass(); $request->jsonrpc = '2.0'; $request->method = 'getQuote'; $request->params = array(1); $request->id = time(); $json = Zend_Json::encode($request); $client = new Zend_Http_Client('http://presentation-zfws/JSONRPC.php'); $response = $client->setRawData($json, 'application/json')->request('POST');
  • 63. JSON-RPC with ZF AND NOW WITH SMD $server = new Zend_Json_Server(); $server->setClass('Kingfoo_Quote'); if ('GET' == $_SERVER['REQUEST_METHOD']) { $server->setTarget('/JSONRPC.php') ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); header('Content-Type: application/json'); echo $smd; return; } $server->handle();
  • 64.
  • 65. Possible with Dojo too, see ZF manual
  • 66.
  • 68. XML, increasingly JSON as message format
  • 69. HTTP verbs define nature of action on resource
  • 70. No spec or standard, more like a 'movement'
  • 71. RESTafarians leave funny comments on blogs and have strong opinions. True SOAP believers are a dying race, it appears. Have a laugh, Google for 'The S stands for Simple'
  • 72. REST GET POST PUT DELETE /quotes Get list Add quote to list Update entire list Delete entire list /quotes/<id> Get quote with id <id> Add subquote (unlikely) Update single quote Delete single quote List = oftern referred to as a 'collection'
  • 73.
  • 74. Now more and more integrated, using Zend_Rest_Controller and Zend_Rest_Route
  • 75. Future versions of ZF (2.0?) will probably have it fully integrated in the controller, using context switching (see posts by Matthew Weier O'Phinney at http://weierophinney.net/matthew/)
  • 76.
  • 77.
  • 78. protected function _initRestroutes() { $this->bootstrap('frontController'); $frontController = Zend_Controller_Front::getInstance(); $router = $frontController->getRouter(); $restRoute = new Zend_Rest_Route($frontController,array(),array('rest')); $router->addRoute('rest', $restRoute); }
  • 79. REST with ZF Zend_Rest_Route detects HTTP verbs like POST and points them to a predefined list of corresponding URI end points. Our example code will result in behaviour like this: URI Module_Controller action GET /rest/quote/ Rest_QuoteController indexAction() GET /rest/quote/:id Rest_QuoteController getAction() POST /rest/quote Rest_QuoteController postAction() PUT /rest/quote/:id Rest_QuoteController putAction() DELETE /rest/quote/:id Rest_QuoteController deleteAction() These additional end points are supported too, as a workaround for environments where PUT or DELETE are blocked by a firewall for example: URI Module_Controller action POST /rest/quote/:id?_method=PUT Rest_QuoteController putAction() POST /rest/quote/:id?_method=DELETE Rest_QuoteController deleteAction() And that counts for every controller in the module named 'rest', as they are all considered RESTful.
  • 80. REST with ZF SERVER -> code example: route + controller CLIENT Zend_Rest_Client -> no $client = new Zend_Http_Client('http://presentation-zfws/rest/index/2'); $response = $client->request(); echo $response->getBody();
  • 81. REST – Response codes Error and response codes ! For example: 200 OK Everything allright 201 Created The object or resources is created 204 Empty body Resource is deleted 400 Bad Request Request is not understood or was malformed. Explanation may be available in the body . 401 Forbidden Permission denied. / credentials invalid 404 Not Found Resource could not be found. 409 Conflict/Duplicate Resource already exists 405 Method Not Allowed The action (POST, PUT, ...) is not allowed on the resource 410 Gone Resource does not/no longer exist 500 Internal server error Something went wrong on the server side 501 Not Implemented The action is not available.
  • 82.
  • 83. RPC vs Resource oriented solutions
  • 84. What do you choose? Depends on your requirements
  • 85.
  • 88. Extending the existing ZF classes and making things even more easy for yourself
  • 89. Thanks for your time Questions? Want us to work for you? [email_address] www.king-foo.be @jonasmarien