jnunemaker/httparty · error · ArgumentError

The URI adapter should respond to #parse

Error message

The URI adapter should respond to #parse

What it means

`uri_adapter` raises ArgumentError unless the provided adapter responds to the class method #parse. HTTParty uses this adapter (default URI) to parse and normalize request paths and redirect targets; Addressable::URI is the common custom choice. Passing a class without .parse (or an instance instead of a class) fails immediately during class configuration.

Source

Thrown at lib/httparty.rb:490

    #     parser Proc.new {|data| ...}
    #   end
    def parser(custom_parser = nil)
      if custom_parser.nil?
        default_options[:parser]
      else
        default_options[:parser] = custom_parser
        validate_format
      end
    end

    # Allows setting a custom URI adapter.
    #
    #   class Foo
    #     include HTTParty
    #     uri_adapter Addressable::URI
    #   end
    def uri_adapter(uri_adapter)
      raise ArgumentError, 'The URI adapter should respond to #parse' unless uri_adapter.respond_to?(:parse)
      default_options[:uri_adapter] = uri_adapter
    end

    # Allows setting a custom connection_adapter for the http connections
    #
    # @example
    #   class Foo
    #     include HTTParty
    #     connection_adapter Proc.new {|uri, options| ... }
    #   end
    #
    # @example provide optional configuration for your connection_adapter
    #   class Foo
    #     include HTTParty
    #     connection_adapter Proc.new {|uri, options| ... }, {foo: :bar}
    #   end
    #
    # @see HTTParty::ConnectionAdapter

View on GitHub (pinned to 8f4a09e343)

Solutions

  1. Pass the class constant: `uri_adapter Addressable::URI` (with `gem 'addressable'` in the Gemfile).
  2. For custom adapters, define the class method: `def self.parse(str); ...; end`.
  3. If configuring from a string, resolve it first: `uri_adapter Object.const_get(config['uri_adapter'])`.

Example fix

# before
uri_adapter 'Addressable::URI'   # String does not respond to #parse -> ArgumentError

# after
require 'addressable'
uri_adapter Addressable::URI
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'adapter must implement .parse' unless adapter.respond_to?(:parse)
uri_adapter adapter

Type guard

parses_uris = ->(klass) { klass.respond_to?(:parse) }

Try / catch

begin
  uri_adapter klass
rescue ArgumentError
  raise ConfigError, "#{klass} must expose a class-level .parse (e.g. Addressable::URI)"
end

Prevention

When it happens

Trigger: `uri_adapter 'Addressable::URI'` (String instead of class constant), `uri_adapter Addressable::URI.new` (instance), `uri_adapter MyAdapter` where MyAdapter does not define `def self.parse(...)`, inside a class that includes HTTParty.

Common situations: Switching to Addressable for international/IRI or stricter normalization support and mistyping the constant, wrapping the adapter in a string from config, or writing a custom adapter that only defines an instance-level parse method.

Related errors


AI-assisted analysis of jnunemaker/httparty@8f4a09e343 (2026-08-21). Data as JSON: /api/errors/45c3fd0a179158d5. Report an issue: GitHub.