Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 788 Bytes

method_override.md

File metadata and controls

20 lines (14 loc) · 788 Bytes

Method override

Changes the request method to POST and writes the original HTTP method to the "X-Http-Method-Override" header.

This can be used to work around technical issues with making non-POST requests, e.g. a faulty HTTP client or server router.

This header is recognized in Rack apps by default, courtesy of the Rack::MethodOverride module.

connection = Faraday.new 'http://example.com/api' do |conn|
  # rewrite all non-GET/POST requests:
  conn.request :method_override

  # rewrite just PATCH and OPTIONS requests:
  conn.request :method_override, rewrite: [:patch, :options]
end

connection.patch('users/12', payload)
#=> sends the request as POST, but with "X-Http-Method-Override: PATCH" header