View Source Plug.MethodOverride (Plug v1.15.3)
This plug overrides the request's POST
method with the method defined in
the _method
request parameter.
The POST
method can be overridden only by these HTTP methods:
PUT
PATCH
DELETE
This plug only replaces the request method if the _method
request
parameter is a string. If the _method
request parameter is not a string,
the request method is not changed.
Parse Body Parameters First
This plug expects the body parameters to be already fetched and parsed. Those can be fetched with
Plug.Parsers
.
This plug doesn't accept any options.
To recap, here are all the conditions that the request must meet in order
for this plug to replace the :method
field in the Plug.Conn
:
- The conn's request
:method
must bePOST
. - The conn's
:body_params
must have been fetched already (for example, withPlug.Parsers
). - The conn's
:body_params
must have a_method
field that is a string and whose value is"PUT"
,"PATCH"
, or"DELETE"
(case insensitive).
Usage
# You'll need to fetch and parse parameters first, for example:
# plug Plug.Parsers, parsers: [:urlencoded, :multipart, :json]
plug Plug.MethodOverride