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:
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:
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):
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:
Ok now lets look into SOAP architecture. There is simple and good sample of building SOAP client in symfony’s cookbook:
And a couple of articles dedicated to creating SOAP server in symfony 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):
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:
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:
And the other one is donation site:
Thanks to everyone for patience!