When a Ruby class includes HTTParty, put the proxy on that class and make requests through it:

class Reports
  include HTTParty
  http_proxy 'proxy.example', 8080
end

response = Reports.get('https://reports.example/monthly')

The example assumes HTTParty is loaded. The proxy method takes a hostname and integer port, with optional username and password arguments. For a permitted public-API test with no proxy account, use an HTTP candidate from the HTTP proxy list for the host and port. Keep the destination URL on get.

Within an instance method of Reports, use self.class.get(...) when the intention is to call that configured class method. Calling the top-level HTTParty module instead can bypass the wrapper whose defaults you just configured.

The same distinction matters when several API wrappers share one application. Give each its intended proxy policy rather than changing HTTParty::Basement globally to repair one class.

HTTParty also exposes per-request proxy options such as http_proxyaddr and http_proxyport. Use those when the route is genuinely part of one request. Class defaults are easier to read when every Reports operation should follow the same path.

Related articles