Refactor to add in a remote api server. The remote api server is used by the cli.

Added some modules for the API, and support of the API.