Refactor of rest layer