Rails5のAPIモードではRack::MethodOverrideがデフォルトでは無効

Rails5のAPIモードを利用してAPIを作っているがHTTPメソッド PUTでの通信がうまくいかなくて調べた結果判明した。

          middleware.use ::Rack::Runtime
          middleware.use ::Rack::MethodOverride unless config.api_only
          middleware.use ::ActionDispatch::RequestId
rails/default_middleware_stack.rb at 5-0-stable · rails/rails · GitHub

なぜ、無効になっているのか調べていた所Rails5のAPIモードの元となったrails-apiのREADMEにこう記載されていた。

Other Middlewares

Rails ships with a number of other middlewares that you might want to use in an API app, especially if one of your API clients is the browser:

https://github.com/rails-api/rails-api/blob/master/README.md

APIのクライアントの1つがブラウザならばこれらのミドルウェアも使う可能性があると記載がある。
つまりAPIであるということは、必ずしもブラウザがクライアントになるわけではないのだからデフォルトでは外しているということだろう。

もし、使用したいミドルウェアがある場合にはconfig/application.rbに追記すれば良い。

config.middleware.use Rack::MethodOverride