Added unit tests for the api controller.  Minor refactoring.

References: https://www.pivotaltracker.com/story/show/63985220