restApi code refactoring