Using YAML to transport data in ActionWebService
Here’s a handy tip for ActionWebService. Sometimes it could be a bit tedious to create the correct SOAP or XML messages to pass back and forth the webservices. If you’re using a Ruby 3rd party client (or even another Rails app as a client) you might want to try out YAML. It’s not entirely conventional but it works like a breeze and it sure beats the hell out of all that XML tagging.
Here’s the code to zip it up to as a YAML object:
yaml_obj = YAML::dump(your_object)
Even quicker — you can use a Hash and stuff everything inside the Hash. Then at the other end:
original_obj = YAML::load(yaml_obj)
There’s YAML for Java, Python, Perl and even Javascript. Check it out here
Don’t come after me if something doesn’t work though — it’s quite experimental at this moment, but it’s a pretty neat alternative to XML tagging.
leave a comment