Integrate metrics support and refactor the code.

Two things really:
- Provide ability to emit metrics for API calls.
- Nicer code organization.
You can do the same thing with `w.Write(marshalledResponse)`