| 1 |
= cowboy_req:method(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy_req:method - HTTP method |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
method(Req :: cowboy_req:req()) -> Method :: binary() |
| 12 |
---- |
| 13 |
|
| 14 |
Return the request's HTTP method. |
| 15 |
|
| 16 |
The method can also be obtained using pattern matching: |
| 17 |
|
| 18 |
[source,erlang] |
| 19 |
---- |
| 20 |
#{method := Method} = Req. |
| 21 |
---- |
| 22 |
|
| 23 |
== Arguments |
| 24 |
|
| 25 |
Req:: |
| 26 |
|
| 27 |
The Req object. |
| 28 |
|
| 29 |
== Return value |
| 30 |
|
| 31 |
The request's HTTP method is returned as a binary string. |
| 32 |
While methods are case sensitive, standard methods are |
| 33 |
always uppercase. |
| 34 |
|
| 35 |
== Changelog |
| 36 |
|
| 37 |
* *2.0*: Only the method is returned, it is no longer wrapped in a tuple. |
| 38 |
* *1.0*: Function introduced. |
| 39 |
|
| 40 |
== Examples |
| 41 |
|
| 42 |
.Ensure the request's method is GET |
| 43 |
[source,erlang] |
| 44 |
---- |
| 45 |
<<"GET">> = cowboy_req:method(Req). |
| 46 |
---- |
| 47 |
|
| 48 |
.Allow methods from list |
| 49 |
[source,erlang] |
| 50 |
---- |
| 51 |
init(Req, State) -> |
| 52 |
case lists:member(cowboy_req:method(Req), [<<"GET">>, <<"POST">>]) of |
| 53 |
true -> handle(Req, State); |
| 54 |
false -> method_not_allowed(Req, State) |
| 55 |
end. |
| 56 |
---- |
| 57 |
|
| 58 |
== See also |
| 59 |
|
| 60 |
link:man:cowboy_req(3)[cowboy_req(3)] |