In the TurboGears book we focused on building web applications, but TurboGears is equally useful for creating web services.
It is remarkably easy to use TurboGears to respond to requests, with JSONified data. TurboGears automatically turns python dictionaries into JSON so you can write something like this:
@expose(template=.templates.hello) @expose(allow_json=True) def hello: return dict(title="Some title", body="Some body")
But, there’s no reason you can’t use JSON and REST as web service type interface. In fact this is now my proffered way to expose “web services.” JSON is lightweight, clean, and has good implementations in multiple languages, and REST is a simple, elegant, and powerful way to organize your requests.
Even thought I prefer JSON and REST, the fact of the matter is that sometimes you need to talk SOAP or XML-RPC — because that’s what the system on the other end talks. This part of TurboGears isn’t as shiny and polished as the JSON story above, but it’s still pretty easy.
You can use TurboZSI to talk SOAP. The documentation could be better, but this is actually pretty cool. You can define
There have been some rumblings about polishing all of this up and making Web Services a more integrated part of the TurboGears story. To me that sounds pragmatically wonderful. We shouldn’t stick our noses up and refuse to play when “enterprise” technologies show up.
Sure, there may be a better way, but playing nice means adapting to the people around you. There’s a lot we can learn from Rails, but as far as I’m concerned Rails can keep their “the anti-enterprise framework” rhetoric for themselves.
Instead, TurboGears should be the “easy to use, easy to extend framework” that plays nice with others, and makes the enterprise better and more fun.”