Author image Bernhard Graf
and 1 contributors


Mojolicious::Plugin::MethodOverride - Simulate HTTP Verbs


Version 0.060


  package My::App;
  use Mojo::Base 'Mojolicious';

  sub startup {
    my $self = shift;





This plugin can simulate any HTTP verb (a.k.a. HTTP method) in environments where HTTP verbs other than GET and POST are not available. It uses the same approach as in many other restful web frameworks, where it replaces the HTTP POST method with a method given by an HTTP header. It is also possible to define a query parameter for the same purpose.

Any token built of US-ASCII letters is accepted as a valid value for the HTTP verb.

Starting with v6.03 Mojolicious has a builtin parameter _method to override the HTTP method. Unfortunately there is neither a way to specify another name, nor to use an HTTP header, nor to disable that feature.


The default HTTP header to override the HTTP POST method is "X-HTTP-Method-Override". Overriding through a query parameter is off by default.

These settings can be changed in the plugin method call as demonstrated in the examples below:

  # Mojolicious
    MethodOverride => {
      header => 'X-Tunneled-Method',
      param  => 'x-tunneled-method',

  # Mojolicious::Lite
  plugin 'MethodOverride',
    header => 'X-HTTP-Method',
    param  => 'http_method';

HTTP header can be disabled by setting to undef:

  # A Mojolicious app, that enables method overriding
  # by query parameter only:
    MethodOverride => {
      header => undef,
      param  => 'x-tunneled-method',

Combination with Charset and Encoding Manipulation

Special attention is required when the application modifies the decoding behaviour of the request object. Before Mojolicious 7.0 a Charset plugin existed, that had to be loaded before this plugin:

  plugin 'Charset', charset => 'Shift_JIS';
  plugin 'MethodOverride';

This Charset plugin was removed in 7.0 and at the time of this writing the programmer is required to do it this way:

  app->types->type(html => 'text/html;charset=Shift_JIS');
    before_dispatch => sub {
  plugin 'MethodOverride';

The reason for the order is that the MethodOverride plugin installs a before_dispatch hook that instantiates the $c->req->url->query object which is kind of self-modifying with implicitely decoding of the query parameters.


Bernhard Graf <graf at>


Please report any bugs or feature requests to bug-mojolicious-plugin-methodoverride at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


Plack::Middleware::MethodOverride, Catalyst::TraitFor::Request::REST::ForBrowsers, HTTP::Engine::Middleware::MethodOverride,


Copyright (C) 2012 - 2016 Bernhard Graf.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See for more information.