Ryan Tomayko put up an article describing the genesis of Kid as an answer for generating responses for web services. Right now, TurboGears produces HTML and JSON as part of the out-of-the-box experience. I definitely expect that we’re going to see the ability to specify a Kid template for XML output.
I think that toward the end of my time in Javaland, an increasing number of the blogs I read seemed to be doubting WS-*. The problem with a specs like WS-* is that when people just sit down to crank out a “standard API”, they’re going to try to take into account every possible need. The best APIs I’ve used, though, are the ones that focus on making the common case as easy as possible, and leaving the door open enough to deal with uncommon issues. These APIs are generally made better because people actually use them.
There’s a reason that people still use XML-RPC, despite the existence of SOAP. It’s simple and it gets the job done for a fair number of scenarios…
Entries (RSS)
September 27th, 2005 at 12:21 pm
I was playing with this idea and thinking about how to overload the turbogears.expose decorator to incluide something like:
turbogears.expose(… html=’html.kid’ xml=’something.xml’ csv=’another’)
then I could have a hook to expose the data in any page in any format. I’m not sure how to resolve the mapping with pretty urls in cherrypy though.
Something like
site.com/people/aaron -> html
site.com/people/aaron.xml -> xml
vs
site.com/people/aaron -> html
site.com/people/aaron?frmt=xml -> xml
September 27th, 2005 at 6:11 pm
Kevin,
People love our ‘builder’ templates in rails which guarantee valid xml (builder ‘features’ not withstanding). Perhaps turbogears could use something similar?
September 28th, 2005 at 7:49 am
I think Kid templates work very nicely for this… Here’s a Rails builder:
xml.response(:code => @code) do
xml.items do
@items.each do |item|
xml.item do
xml.sku(item.product.sku)
xml.description(item.product.description)
xml.unit_price(item.product.list_price, :currency => “usd”)
xml.quantity(1)
end
end
end
end
It’s basically just the same thing inverted. Rather than a little XML in your Ruby, you get a little Python in your XML