Imagine we need to pass a a number structured objects to the web application – for instance, locale, layout settings and a definition of some query. This can be easily done with JSON or XML similar to the following fragment:
<Locale>en</Locale>
<Layout>
<Block id="header">hide</Block>
<Block id="footer">hide</Block>
<Block id="navigation">minimize</Block>
</Layout>
<Query>
<What>water</What>
<When>
<Start>2010-01-01</Start>
</When>
</Query>
However, passing such structures with HTTP implies (roughly speaking) HTTP POST.
Now assume we’re limited to HTTP GET. Is there some kind of a standard solution for encoding structured data in HTTP GET request parameters?
I can easily imagine something like:
Locale=en&
Layout.Block.header=hide&
Layout.Block.footer=hide&
Layout.Block.navigation=minimize&
Query.What=water&
Query.When.Start=2010-01-01
But what I’m looking for is a “standard” syntax, if there’s any.
ps. I’m surely aware of the problem with URL length. Please assume that it’s not a problem in this case.
pps. I’d be also greatful for links to key-value pair URL APIs (like Paypal NVP) which you think to be worth taking a look at.
ppps. We’re certainly forseeing the callback URLs but we need HTTP GET key-value pairs as well. The question focuses on the latter.
To my knowledge, there are no standards for passing structured data using GET. There are a handful of conventions (the PHP/RoR example above possibly the most prevalent), but nothing that has reached any level of maturity, documentation, reference implementation etc… to be considered a standard.
And it’s not too surprising a simple standard hasn’t emerged. There are open questions whose answers depend upon specifics of the situation. Should the URL be transparent (as visible query parameters) or opaque (e.g. base64 encoded). Can compression be used? Can/should/must other representations be used/supported, e.g. JSON, binary XML or even Google’s protocol buffers). How is URL overflow handled? 10 different people might all give different answers about what needed based on their situation. A standard could attempt to address all these concerns, but it would then be far from simple.
Even if there were a standard, would it make sense to follow it?
It’s desirable, comforting even, to follow a standard, knowing that your work is building on the road-tested work of respected field-experts and engineers, and knowing that we are invited to the party and play with other systems that follow the same standard. But when the requiremtents are diverse, as they are here, a standard will typically only give you a middle-ground solution, a medium of comprimise. And when you’ve only got 2K to play with, comprimising is probably last on your list!
Roll your own and you’ll be sure to get exactly what you want. I’d go for representing as binary XML or protocol buffers, gzipped and base64 encoded, but you’re millage may vary.
Either way, good luck!