Skip to main content

HTTP Client

We use Faraday as our preferred HTTP client in our Ruby codebases.

Farady is highly configurable, but has a simple and consistent interface. As an HTTP client interface, it also allows its underlying HTTP adapter to be swapped out.

Usage#

require 'faraday'
def ThanxClient  def get(path)    client.get(path)  end
private
  def client    @client ||= Faraday.new("https://api.thanx.com/") do |faraday|      faraday.request  :json      faraday.response :json      faraday.adapter  :net_http    end  endend
client = ThanxClient.newresponse = client.get('purchases')
response.status  # => 200response.headers # => {"content-type" => ...}response.bodyh   # => {purchases: [...]}

Examples#