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