Implement protocol in API server

**WIP - do not merge**