Refactor REST server