Bug 989074: better support for API methods

The new @apimethod decorator handles returning JSON in a context-aware
manner.  The entire app also handles exceptions in an appropriate
fashion, serving HTML to browsers and JSON to clients.

Docs and tests included.