May 20
Digg
Stumbleupon
Technorati
Delicious

Web Services and Symfony

Hi, have you ever thought about building web services on top of symfony? Or write client to access web services from symfony? Here we will provide some thoughts about work with web services using symfony.

Web service is something you need if you feel that your web application need to communicate with the rest of the world. A lot of web services are implemented using a REST style architecture, some others using a SOAP one, some other using.. Well lets stop here and look what is SOAP and REST as they are actually major players in this game.

The main advantages of REST web services are:

  • Lightweight – not a lot of extra xml markup
  • Human Readable Results
  • Easy to build – no toolkits required

SOAP also has some advantages:

  • Easy to consume – sometimes
  • Rigid – type checking, adheres to a contract
  • Development tools

For consuming web services, its sometimes difficult to figure out which is easier. e.g. Google web services hard to consume b/c it uses SOAP headers, and a number of other things that make it kind of difficult.
On the converse, Amazon’s REST web service (they also provide SOAP though) is complicated to parse b/c it can be highly nested, and the result schema can vary quite a bit based on what you search for.

First of all it’s very important to mention that starting from symfony 1.2 – it has RESTful architecture (one more plus for using RESTful approach). Here are some symfony 1.2 slides from Fabien Potencier regarding that:

http://fabien.potencier.org/talk/16/symfony-camp-2008-REST

It gives good introduction into using REST in symfony.
I believe next step you can use to learn is actual symfony manual where they provided separate chapter dedicated to using of REST:

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/15

It’s also worth to pay attention to some existing REST-related plugins, e.g. interesting is plugin that provides restful authentication features (supports Propel only):

http://www.symfony-project.org/plugins/sfRestfulAuthenticationPlugin

I’d recommend though to dig a little bit more into world of REST (or REST of world ?) using these articles I found. They explains how to build REST handler from scratch and code can be easily mapped on symfony:

PHP REST Server:
http://www.lornajane.net/posts/2008/PHP-Rest-Server-part-1-of-3
http://www.lornajane.net/posts/2008/PHP-Rest-Server-part-2-of-3
http://www.lornajane.net/posts/2008/PHP-Rest-Server-part-3-of-3

Create a REST API:
http://www.gen-x-design.com/archives/create-a-rest-api-with-php/
http://www.gen-x-design.com/archives/making-restful-requests-in-php/

Ok now lets look into SOAP architecture. There is simple and good sample of building SOAP client in symfony’s cookbook:

http://snippets.symfony-project.org/snippet/135

And a couple of articles dedicated to creating SOAP server in symfony using ckWebServicePlugin:

http://blog.barros.ws/2008/11/16/soap-webservice-in-symfony/
http://tohenk.wordpress.com/2009/09/17/dynamic-web-service-using-ckwebserviceplugin/

It seems that this plugin is a bit outdated though but using comments it’s easy to get it working by doing some small changes to its code.

The alternative way to build SOAP server/client is using of resurrected library (there were not releases until last month for at least a couple of years):

http://sourceforge.net/projects/nusoap/

Yes, it’s good old NuSOAP which you can put into symfony’s lib folder and get direct access to it from your symfony code. It provides both client and server SOAP functionalities and some guys think that this is only real way to work with SOAP on PHP 🙂

And on last note I’d like to mention that Zend framework provides support for both formats and this can be used in symfony using Zend bridge:

http://framework.zend.com/manual/en/zend.soap.html
http://framework.zend.com/manual/en/zend.rest.html

So that’s quickly but hopefully informative about web services.
Oh well and since there are so many references in this post I guess a couple more wont mess it up 🙂

Recently I laid an eye on these new open-source symfony projects which are pretty interesting.
So first is one more “todo” project:

http://www.nacho-martin.com/list-check-an-open-source-symfony-project

And the other one is donation site:

http://github.com/bshaffer/Donate-Nashville

Thanks to everyone for patience!


Author: symfonian

3 Comments

chok
August 6, 2010

About webservices, I’ve just released sfHarmonyPlugin : http://www.symfony-project.org/plugins/sfHarmonyPlugin. This plugin allow to use webservice by using model or action. It’s a generic gateway and soap and amf plugin will come soon.

[…] on Wikipedia Web Services and Symfony The origina Jobeet website How Ryan Tomayko explained REST to his wife This entry was posted in […]

Comments RSS TrackBack Identifier URI

Leave a comment