refactored api_connection to support User-Agent header