{"record":{"id":"45c3fd0a179158d5","repo":"jnunemaker/httparty","slug":"the-uri-adapter-should-respond-to-parse","errorCode":null,"errorMessage":"The URI adapter should respond to #parse","messagePattern":"The URI adapter should respond to #parse","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/httparty.rb","lineNumber":490,"sourceCode":"    #     parser Proc.new {|data| ...}\n    #   end\n    def parser(custom_parser = nil)\n      if custom_parser.nil?\n        default_options[:parser]\n      else\n        default_options[:parser] = custom_parser\n        validate_format\n      end\n    end\n\n    # Allows setting a custom URI adapter.\n    #\n    #   class Foo\n    #     include HTTParty\n    #     uri_adapter Addressable::URI\n    #   end\n    def uri_adapter(uri_adapter)\n      raise ArgumentError, 'The URI adapter should respond to #parse' unless uri_adapter.respond_to?(:parse)\n      default_options[:uri_adapter] = uri_adapter\n    end\n\n    # Allows setting a custom connection_adapter for the http connections\n    #\n    # @example\n    #   class Foo\n    #     include HTTParty\n    #     connection_adapter Proc.new {|uri, options| ... }\n    #   end\n    #\n    # @example provide optional configuration for your connection_adapter\n    #   class Foo\n    #     include HTTParty\n    #     connection_adapter Proc.new {|uri, options| ... }, {foo: :bar}\n    #   end\n    #\n    # @see HTTParty::ConnectionAdapter","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/jnunemaker/httparty/blob/8f4a09e343b94de9f934f388028ca97620c9b378/lib/httparty.rb#L472-L508","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Pass the class constant: `uri_adapter Addressable::URI` (with `gem 'addressable'` in the Gemfile).","For custom adapters, define the class method: `def self.parse(str); ...; end`.","If configuring from a string, resolve it first: `uri_adapter Object.const_get(config['uri_adapter'])`."],"exampleFix":"# before\nuri_adapter 'Addressable::URI'   # String does not respond to #parse -> ArgumentError\n\n# after\nrequire 'addressable'\nuri_adapter Addressable::URI","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'adapter must implement .parse' unless adapter.respond_to?(:parse)\nuri_adapter adapter","typeGuard":"parses_uris = ->(klass) { klass.respond_to?(:parse) }","tryCatchPattern":"begin\n  uri_adapter klass\nrescue ArgumentError\n  raise ConfigError, \"#{klass} must expose a class-level .parse (e.g. Addressable::URI)\"\nend","preventionTips":["Pass the class constant, never a String or instance.","Cover custom adapters with a spec asserting `.respond_to?(:parse)`.","Add the addressable gem explicitly when using Addressable::URI."],"tags":["ruby","httparty","configuration","validation","argument-error","uri"],"backgroundTag":"invalid-configuration-value","analyzedSha":"8f4a09e343b94de9f934f388028ca97620c9b378","analyzedAt":"2026-08-21T19:30:42.003Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}