js + rest refactoring