Refactoring dynamic api controller