File: method_override.md

package info (click to toggle)
ruby-faraday-middleware 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 376 kB
  • sloc: ruby: 2,388; sh: 15; makefile: 6
file content (20 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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](https://www.rubydoc.info/github/rack/rack/Rack/MethodOverride) module.

```rb
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
```