Refactor: Separate the code to handle the http request and the rpc in two functions.