Extract HTTP and JSON code to client.go