View Source Plug.MethodOverride (Plug v1.15.2)
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:
PUTPATCHDELETE
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
:methodmust bePOST. - The conn's
:body_paramsmust have been fetched already (for example, withPlug.Parsers). - The conn's
:body_paramsmust have a_methodfield 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