Refactor HTTP request code

Refactor code to use a wrappedHttpRequest function to wrap the repeated HTTP request logic