cowboy_req:method(3)

NAME

cowboy_req:method - HTTP method

DESCRIPTION
    method(Req :: cowboy_req:req()) -> Method :: binary()

Return the request's HTTP method.

The method can also be obtained using pattern matching:

    #{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
    <<"GET">> = cowboy_req:method(Req).

Allow methods from list
    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

cowboy_req(3)