X-HTTP-Method-Override

550 views
Skip to first unread message

Shawn McDonald

unread,
Feb 10, 2014, 3:11:11 PM2/10/14
to ruby-...@googlegroups.com
Is there a way to use an X-HTTP-Method-Override header with Grape?

If I write a PATCH request into my API, but send a PUT request with an X-HTTP-Method-Override header, I will receive a 405 response. Is there something I have to do in Grape, or do I need to set up some other type of middleware?

Daniel Doubrovkine

unread,
Feb 11, 2014, 4:36:07 PM2/11/14
to ruby-...@googlegroups.com
I think you just need to add Rack::MethodOverride into your middleware, above Grape.


On Mon, Feb 10, 2014 at 3:11 PM, Shawn McDonald <sh...@spoonrocket.com> wrote:
Is there a way to use an X-HTTP-Method-Override header with Grape?

If I write a PATCH request into my API, but send a PUT request with an X-HTTP-Method-Override header, I will receive a 405 response. Is there something I have to do in Grape, or do I need to set up some other type of middleware?

--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

dB. | Moscow - Geneva - Seattle - New York
code.dblock.org - @dblockdotorg - artsy.net - github/dblock

Shawn McDonald

unread,
Feb 12, 2014, 3:24:14 PM2/12/14
to ruby-...@googlegroups.com
I moved Rack::MethodOverride to the top, but this doesn't seem to prevent a 405 response.

Here's how it looks when I run rake middleware for the rails app:

use Rack::MethodOverride
use Rack::Cors
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007fadcc1d7ca8>
use Rack::Runtime
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use OmniAuth::Builder
use OmniContacts::Builder
run MyApp::Application.routes

Shawn McDonald

unread,
Feb 12, 2014, 4:34:31 PM2/12/14
to ruby-...@googlegroups.com
After playing with it, I realized that I can only override POST requests with an X-HTTP-Method-Override header. I can't override PUT/PATCH/DELETE/GET requests. Is this supposed to be the behavior of Rack::MethodOverride, or should there be a way to use it to override other types of requests?

Shawn McDonald

unread,
Feb 12, 2014, 4:44:46 PM2/12/14
to ruby-...@googlegroups.com
Never mind, I found that's the way it's supposed to behave in the source. I guess I'll have to write my own middleware or change the requests to POST.

Thanks for your help. Pointing me to Rack::MethodOverride put me on the right path.

Daniel Doubrovkine

unread,
Feb 13, 2014, 7:20:44 AM2/13/14
to ruby-...@googlegroups.com
If you write a middleware that does more than that, post a link here. Thx.
Reply all
Reply to author
Forward
0 new messages