Joël Perras - Demystifying Webservices in CakePHP

Written by Graham Weldon on Mon, Jul 13th 2009, 14:06

Joël's presentation on Web Services and CakePHP identifies important and interesting points that really demystify both implementation of datasources, and what web services mean for developers trying to take advantages of their offerings.

A Web Service is a defined interface. The interface is made known and public, however the implementation may not be known (and its not really important). The developer should be interested in the data supply and the data returned from the web service.

Various mechanisms are available for communicating with a web service. Such as: RPC, SOA, REST and more.

Much of this presentation covered best practices, better practices, and why people tend to make decisions like implementing components when they really want datasources, as well as implementing datasources, and going about the implementation the wrong way. In the case of web services datasources implementation, curl is presented as a good example of something that works, but a better solution is available through the use of HttpSocket. HttpSocket being one of the CakePHP core libraries provided, allowing a complete implementation of Http communication, extending the CakeSocket class.

Authentication and Authorization options were presented, with specific reference to OpenID and OAuth. Authentication and Authorzation are part of the application flow graph. This means implementation should be at the controller level, and in terms of implementing easily managed pluggable sections of code in cakephp converntions, this means a component.

Data Sources are the closest layer to the actual data. Correct implementation of a data source will allow models to connect and communicate in a transparent fashion, meaning easy access to data in a standard way.

The basics of a datasource should implement the following: __construct, listSources, describe, create, read, update, delete as well as defining $_schema. Some great datasource examples can be seen in the core. When implementing a datasource, to ensure maximum use and compatibility, try to make use of CakePHP libraries such as HttpSocket in the place of curl.

Google Charts was presented as a good example of what should not be implemented as a datasource. The data in this instance is handed by some other data source, and the formatted chart request is sent with an image response supplied. This is more appropriate for a helper than a datasource. Joël mentioned that he has a partial google charts helper that he would be willing to share if someone asked.


CakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHP CakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHPCakePHP