Nikita Kazakov
Nikita Kazakov
1 min read


I like using Typhoeus for making API calls in Ruby on Rails because the interface is simple. Here’s how I use it.

Add it to your GEMFILE from Typhoeus github page.

It’s not what I’d prefer, but you could make GET requests like this:

request = Typhoeus.get("", followlocation: true)

I prefer to have one consistent way of doing things even if the syntax is a bit longer. Here’s how I structure my API calls.

request =, options)

Let’s make an API call to icanhazdadjoke API:

request =
  method: :get,
  headers: { 'Accept': 'application/json', 'User-Agent': 'Bob Smith' },
  followlocation: true

response =      # Makes the API call

# A few methods to analyze the response
response.body               # "{\"id\":\"KBsWnO711Dd\..." Returns JSON as string

data = JSON.parse(response.body)   # Converts string to Ruby Object
data['joke']                       # The joke

Let’s do another API call to EventBrite API. You’ll need your own private API key if you want to replicate this yourself. I’m going to create a wrapper class in the app/lib Rails folder.

# app/lib/event_brite_api.rb

class EventBriteApi
  BASE_URL = ''

  def initialize

  def fetch_event(id)
    request =
      "#{BASE_URL + id.to_s}",
      followlocation: true,   # Without this, it won't redirect automatically
      method: :get,
      params: { expand: 'ticket_classes' },
      headers: { 'Authorization': "Bearer #{APIKEY}" }


Let’s go to Rails console rails console in the terminal and try it out.

event_id = 86569213849   # Returns JSON data

Note that I passed in params as an option in Typhoeus.

request =
      method: :get,
      params: { expand: 'ticket_classes' }

# It would access params like this: