added rest protocol

+ a few more tests
+ refactoring to be more testable.
+ new commands