Skip to content

Instantly share code, notes, and snippets.

@veloper
Forked from mislav/gist:938183
Created November 5, 2013 14:29
Show Gist options
  • Select an option

  • Save veloper/7319841 to your computer and use it in GitHub Desktop.

Select an option

Save veloper/7319841 to your computer and use it in GitHub Desktop.

Revisions

  1. @mislav mislav created this gist Apr 23, 2011.
    34 changes: 34 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    connection = Faraday::Connection.new('http://example.com') do |builder|
    builder.request :url_encoded # for POST/PUT params
    builder.adapter :net_http
    end

    # same as above, short form:
    connection = Faraday.new 'http://example.com'

    # GET
    connection.get '/posts'

    # POST payload
    payload = {:title => 'Example'}
    connection.post '/posts', payload

    # now again, over SSL
    # verify_mode is automatically set to OpenSSL::SSL::VERIFY_PEER
    connection = Faraday.new 'https://example.com'

    # turn off SSL
    # (no use-case for this, really)
    connection = Faraday.new 'https://example.com', :ssl => false

    # turn off peer verification
    connection = Faraday.new 'https://example.com', :ssl => {:verify => false}

    # other SSL options
    connection = Faraday.new 'https://example.com', :ssl => {
    :client_cert => ...,
    :client_key => ...,
    :ca_file => ...,
    :ca_path => ...,
    :cert_store => ...
    }