turning the tables w/ wisdom
for the past few weeks, i've been working on a sample app for the exyus web engine called codebreaker. this is a simple app and only exists to help me exercise the engine to discover holes, bugs, etc. but it's been a fun project.
one thing that i've learned in the last several months of working on this HTTP/REST engine, is that it's not all that difficult to build apps that are 'mime-type neutral'. in other words, you can design the app with one media-type in mind (XML) and then provide support for a another media-type (JSON) without all that much trouble. i used to do this by building separate APIs and URIs for each representation type. bad! now i use a single interface and allow clients to select the media-type they wish for their representations.
anyway, to learn how to do this properly, i've focused on building data-centric representations first (XML, Atom, JSON) and then adding an XHTML representation for the common browser. this forced me to build a solid data API first. well, for this game, i focused on the XHTML API first (makes sense, right?) and have just now started working on the XML/JSON representations. interesting results.
first, this app has a bit of workflow. now my API needs to reflect that. that means hypermedia (ta-da!). i'm still struggling a bit with how to represent hypermedia links in XML, JSON, but i have some ideas.
second, i use a client-cookie to identify the workstation (session that lasts between reboots). that means my data APIs need to support cookies, too. not a big deal, but some added work (command-line apps need state, too!). btw - i don't like working with cookies and prefer using HTTP Auth instead. never thought i'd say that...
finally, i use redirects quite a bit in the app to make sure i can point the user to a client-specific URI (based on the cookie). that means the client API coding also needs to support following redirects. lucky for me, the .NET implementation of
WebRequest/WebResponse automatically follow redirects. i guess this could be bad at times, but for me it's perfect!
so i turned the tables on this development effort. XHTML first, data API second. i've just about come full circle from the days when i built web apps for the browser client alone. but this round trip has left me much wiser.