Skip to content

Instantly share code, notes, and snippets.

@mlsaito mlsaito/
Last active Jun 3, 2019

What would you like to do?
Specify SSL version (TLS 1.2) on HTTParty - a Ruby client library


Some vendors require you to call their API via TLS 1.2 and I don't see that much documentation on how to do this.

2 ways to make an HTTP request using HTTParty:

  1. Directly calling Class method.
# Notice the `ssl_version` option, to specify ssl version of the HTTP request
response = HTTParty.get('', ssl_version: :TLSv1_2)
  1. Wrap HTTParty in your own class.
class StackExchange
  include HTTParty
  base_uri ''
  # HTTParty would inherit this option
  ssl_version :TLSv1_2

  def initialize(service, page)
    @options = { query: { site: service, page: page } }

  def questions
    self.class.get("/2.2/questions", @options)

  def users
    self.class.get("/2.2/users", @options)

stack_exchange ="stackoverflow", 1)
puts stack_exchange.questions
puts stack_exchange.users


Paypal made a dedicated endpoint mainly for this purpose, since they're one of the vendors who requires such ssl version. Reference:

Confirm if TLS 1.2 is used properly and received by the server.


Expected Output:


You could also do a pry on your staging / production server and executing HTTParty.get directly. If you encounter an error, you must upgrade the OPENSSL library on your machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.