I just wrote an article on How to create Magento AMF server extension over at Inchoo.net so I figured why not squeeze another one here on ActiveCodeline.com. If there is anything I like about Zend its service components. Creating a REST, SOAP or AMF server in Zend is a breeze. Since Magento is built on top of Zend, the job of creating a simple REST server extension is really simple.
For your module to act as a basic REST server you need only 3 files. MyCompany_MyModule.xml that goes under the /app/etc/modules/ folder. Then IndexController.php that goes under the /app/code/local/MyCompany/MyModule/controllers/IndexController.php. And last but not least the config.xml file that goes under the /app/code/local/MyCompany/MyModule/etc/ folder.
Inside your IndexController.php file you will actualy hold the code for your REST server (Zend_Rest_Server).
Here is an example of indexAction from my IndexController.php file:
... public function indexAction() { $server = new Zend_Rest_Server(); $server->setClass('My_Service_Class'); $server->handle(); } ...
The above code is the “server”. Now we need to make all of this accessible via Url, so we can access that server. We need to add entry to config.xml file. Below is the full example of my config.xml file.
<?xml version="1.0"?> <config> <modules> <MyCompany_MyModule> <version>1.0.0</version> </MyCompany_MyModule> </modules> <frontend> <routers> <mymodule> <use>standard</use> <args> <module>MyCompany_MyModule</module> <frontName>myrestserver</frontName> </args> </mymodule> </routers> </frontend> </config>
Above piece of code sets access to REST server on Url like http://server/store/index.php/myrestserver.
Thats it.