Refactored API code into a separate general trait (c.f. lift code)