Clean up API implementation using middleware
Use implicit object conversion with #toJSON

JSON.stringify, if told to convert an object with a #toJSON method, will instead
stringify the result of the #toJSON method.