1Plack::Middleware::MethUosdeOrveCrornitdrei(b3u)ted PerlPlDaoccku:m:eMnitdadtlieownare::MethodOverride(3)
2
3
4
6 Plack::Middleware::MethodOverride - Override REST methods to Plack apps
7 via POST
8
10 version 0.20
11
13 In your Plack app:
14
15 use Plack::Builder;
16 builder {
17 enable MethodOverride;
18 $app;
19 };
20
21 PUT via a query parameter in your POST forms:
22
23 <form method="POST" action="/foo?x-tunneled-method=PUT">
24 <!-- ... -->
25 </form>
26
27 Or override it via the "X-HTTP-Method-Override" header in a request:
28
29 my $req = HTTP::Request->new(POST => '/foo', [
30 'X-HTTP-Method-Override' => 'PUT'
31 ]);
32
34 Writing REST
35 <http://en.wikipedia.org/wiki/Representational_State_Transfer>ful apps
36 is a good thing, but if you're also trying to support web browsers, it
37 would be nice not to be reduced to "GET" and "POST" for everything.
38
39 This middleware allows for "POST" requests that pretend to be something
40 else: by adding either a header named "X-HTTP-Method-Override" to the
41 request, or a query parameter named "x-tunneled-method" to the URI, the
42 client can say what method it actually meant. That is, as long as it
43 meant one of these:
44
45 · GET
46
47 · POST
48
49 · HEAD
50
51 · PUT
52
53 · DELETE
54
55 · OPTIONS
56
57 · TRACE
58
59 · CONNECT
60
61 · PATCH
62
63 If so, then the "REQUEST_METHOD" in the PSGI environment will be
64 replaced with the client's desired value. The original request method
65 is always stored under the "plack.original_request_method" key.
66
68 These are the named arguments you can pass to "new". Or, more likely,
69 on the "enable" line in your "builder" block, as in
70
71 enable 'MethodOverride', header => 'X-HTTP-Method', param => 'my_method';
72
73 "header"
74 Specifies the HTTP header name which specifies the overriding HTTP
75 method.
76
77 Defaults to "X-HTTP-Method-Override", as used by Google for its APIs.
78
79 "param"
80 Specifies the query parameter name to specify the overriding HTTP
81 method.
82
83 Defaults to "x-tunneled-method".
84
86 This module gleefully steals from
87 Catalyst::TraitFor::Request::REST::ForBrowsers by Dave Rolsky and the
88 original version by Tatsuhiko Miyagawa (which in turn stole from
89 HTTP::Engine::Middleware::MethodOverride). Thanks to Aristotle
90 Pagaltzis <http://plasmasturm.org/> for the shove in this direction, to
91 Matt S Trout <http://www.trout.me.uk/> for suggesting that it be
92 implemented as middleware, and to Hans Dieter Pearcey
93 <http://www.weftsoar.net/> for convincing me not to parse body
94 parameters.
95
97 · Tatsuhiko Miyagawa <miyagawa@bulknews.net>
98
99 · David E. Wheeler <david@justatheory.com>
100
101 · Aristotle Pagaltzis <pagaltzis@gmx.de>
102
104 This software is copyright (c) 2015 by Tatsuhiko Miyagawa, David E.
105 Wheeler, Aristotle Pagaltzis.
106
107 This is free software; you can redistribute it and/or modify it under
108 the same terms as the Perl 5 programming language system itself.
109
110
111
112perl v5.28.0 2018-05-2P5lack::Middleware::MethodOverride(3)