Wednesday, 24 January 2007
Article: Add a REST Web Service to CakePHP |
| |
|
| |
A tutorial by Sam DeVore over at the Bakery blog talks about how to add a simple REST web service to a CakePHP site. For the uninitiated, Representational State Transfer (REST) is a software architectural style for distributed hypermedia systems like the World Wide Web.
Sam explains the subject with the help of an example. He uses the example to request the list of countries from a database to share among many applications. He uses it to have consistent set of country_id's among a couple of different applications that all share the same database back end: REALBasic Application, Aperture Plug-in and a CakePHP web application.
The first step he does is to turn on web services in config/core.php by uncommenting this line—
[]define('WEBSERVICES', 'on');
Then he makes a rest.php file in controllers/components and in views/helpers which he illustrates with download codes. He follows it up by making a folder in views/layouts called 'rest' and puts a default.thtml file in it.
After dealing with the primary formalities, he goes on to create the SQL data structure with the help of a download code. A Model file is also created for this purpose—models/country.php. He creates a controller and adds action to load all the data. He says this can be done in a set of SQL calls but he provides his own example to do carry out this process.
After this steps are carried out, the result is that when you call view your REST client application in http://your.server.example.com/rest/countries/listing you will get a little XML response back, and that is the basic getting started with requesting some data with REST, he explains. |
| |
|
Read the Article
|
| |
|
|
| |
|
|
| |
|