Add HTTP server and refactor JSON-RPC functions