aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/cowboy_req.method.asciidoc
blob: bb3ad6ee775c162024932de4d944f0311689fe68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
= cowboy_req:method(3)

== Name

cowboy_req:method - HTTP method

== Description

[source,erlang]
----
method(Req :: cowboy_req:req()) -> Method :: binary()
----

Return the request's HTTP method.

The method can also be obtained using pattern matching:

[source,erlang]
----
#{method := Method} = Req.
----

== Arguments

Req::

The Req object.

== Return value

The request's HTTP method is returned as a binary string.
While methods are case sensitive, standard methods are
always uppercase.

== Changelog

* *2.0*: Only the method is returned, it is no longer wrapped in a tuple.
* *1.0*: Function introduced.

== Examples

.Ensure the request's method is GET
[source,erlang]
----
<<"GET">> = cowboy_req:method(Req).
----

.Allow methods from list
[source,erlang]
----
init(Req, State) ->
    case lists:member(cowboy_req:method(Req), [<<"GET">>, <<"POST">>]) of
        true -> handle(Req, State);
        false -> method_not_allowed(Req, State)
    end.
----

== See also

link:man:cowboy_req(3)[cowboy_req(3)]