REST - why don’t people just use simple REST webservices?
Friday, September 28th, 2007One of the things we’re doing with ewelike is connecting to webservices.
It’s trivial to open a stream or CURL to a REST querystring based API - just use sprintf and urlencode to put your parameters into the URL’s querystring and then call it. Even if you need to change the parameters you can easily iterate a hash array of name value pairs and put those into the querystring - it’s just easy.
So, why do some organisations insist on xml-rpc or SOAP webservices? Especially as they all take simple types anyway as arguments.
If you provide REST APIs then they’re trivial to write, and trivial to test in various permutations. They also have another advantage called “performance” because they’re about as close to the knuckle as you can get without opening a custom port and inventing some new protocol.
Let’s think about SOAP and what it’s doing on both sides;
On the client you’re instantiating/loading a library.
Then building some object representation of the data you want to send
That object representation is then serialised into xml (sometimes with an additional step which involves building the model using the DOM or similar)
The call is then made and the serialised xml is sent over the wire to the service.
The service’s web server then gets the call and the data. It redirects it to something that can handle the call.
Data is de-serialised and re-instanced into an object representation so it can be used.
The service does what it needs to and then serialises the data to send it back
The calling client takes the returned data, deserialised and then used
That’s a lot of work. REST cuts down on a few of these steps (and the API docs are far easier - plus there’s no need to stubs and proxies to handle the calls) and it just looks cleaner.
If you don’t believe me then download something like simpletest (we use it for more than testing just PHP) and build yourself a test rig for your web services. For REST you’ll be able to try legal and illegal calls and you’ll code it up in minutes. Try doing that for SOAP or xml-rpc.
Here the sermon ends….
