Skip to content

Method override

mislav edited this page Aug 30, 2012 · 4 revisions

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

This can be used to work around technical issues with making non-POST requests, e.g. 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

(Please note: This wiki has been closed, and turned into in-repo Markdown documents. You can find them in the repository's docs/ directory. This wiki does not take new edits.)

Clone this wiki locally