Search code examples
rubyfaradaypreflight

Preflight OPTIONS request with Faraday gem


How would I make a preflight request with Faraday? It seems there is a name collision.

# Create a connection
conn = Faraday.new('http://example.com')

# GET request
conn.get # => #<Faraday::Response

# POST request
conn.post # => #<Faraday::Response

# OPTIONS request collides?
conn.options # => #<struct Faraday::RequestOptions

Solution

  • As one might see, the syntactic sugar is provided for all methods, save for :options. To perform such a request, one might call the wrapped Connection#run_request directly:

    conn.run_request(:options, nil, nil, nil)