restapi code refactoring