<p>It’s been <a href="http://en.wikipedia.org/wiki/Indirection">famously said</a> that “all problems in computer science can be solved by another level of indirection.”</p><p>While you won’t see most Web / REST APIs providing strictly recursive data structures—after all, JSON and XML are incapable of strict recursion—they do love layer after layer and level after level of structure.</p><p>That means your client code and workflows have to be ready to “dive down” layer by layer to get the data you want. Often this means descending through lists/levels that almost always have just one item. They’re not true <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singletons</a>, but they can seem to be.</p><p>You might connect to find spreadsheet data, but then have to select a document-set, then a document, then a worksheet, and then rows and columns. Or if you want a list of recent emails, you might have to select an account, then a mailbox, then wade through a list of threads, then a list of messages in each thread, to finally get to messages. Each message then might be a multi-part document, including different formats (HTML and text, natch) and maybe some attachments.</p><p>We may think our task is simple and lament the many levels it takes to “get some data!” or “get some emails!” but the API providers have to think much more globally. So learn to love the generality and take the indirection in stride. Or just grin and bear it. Many levels of indirection is the price we pay for having extremely flexible, network-accessible resources—wonderful tools, often free, that scale to global requirements.</p>
Get New Tutorials Delivered to Your Inbox
New tutorials will be sent to your Inbox once a week.