refactoring existing code into rest api