I’ve been playing with a Ruby micro-framework for web apps called Sinatra. Billed as a DSL (Domain Specific Language) for minimal effort web apps, Sinatra actually seems to excel at a particular task near and dear to my heart: URL-based web services. If you’re not familiar with a REST API, this is basically a web service queried entirely through structured URLs. Something like http://twitter.com/statuses/public_timeline.format for the Twitter public timeline in RSS or XML or whatever.
These are the services that your nerd friends use to mash up Google maps, create widgets or build useful browser extensions.
They actually tend to follow the Linux philosophy of a system
constructed of simple commands to produce, consume or alter data which
can be strung together for aggregate value. This proves to be an
efficient and effective architecture. A sufficiently robust set of
REST APIs is really a sophisticated SOA in the making.
So, Sinatra really shines at building these services. Here’s an example of a boring handler:
get '/' do puts 'Looky. I am an index.' end
But we can imagine an even more interesting handler:
get '/:edi_address/list' do puts db.getDocuments(params[:edi_address]).to_jsonend
And we could query this on a timer with AJAX and continually list
documents as they stream in to the mailbox at this address. As you can
see, aside from all the hidden database logic, this approach is very
clear, very concise and very readable compared to something SOAP-based.
Throw a few more handlers in here to tap in to other data sources in
your system and you have a full, web developer-friendly programming
toolkit to add value to your ecosystem.
Plus, it’s a nice hat.
