From d2a3f2cedd7c00d0933222aed9c06b3149aa4db4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= method
is GET, and a 405 error
otherwise.
The request method can be retrieved directly:
#{method := Method} = Req.
Or using a function:
The HTTP version can be retrieved directly:
#{version := Version} = Req.
Or using a function:
The scheme, host, port, path and query string components of the effective request URI can all be retrieved directly:
Or using the related functions:
cowboy_req:uri/1,2
function. By default, an absolute
URI is returned:The protocol relative form:
The absolute URI without a query string:
URI = cowboy_req:uri(Req, #{qs => undefined}).
A different host:
Cowboy provides functions to retrieve one or all bindings.
To retrieve a single value:
undefined
will be returned. A different default value
can be provided:Value = cowboy_req:binding(userid, Req, 42).
To retrieve everything that was bound:
...
qualifier.To retrieve the segments captured from the host name:
HostInfo = cowboy_req:host_info(Req).
And the path segments:
Cowboy provides two functions to access query parameters. You can use the first to get the entire list of parameters.
id
parameter is not an integer,
or when the lang
parameter is empty. At the same time, the
value for id
will be converted to an integer term:lang
key is not found. It will not be used if
the key is found but has an empty value.The get the raw value:
When the header is missing from the request, undefined
will be returned. A different default can be provided:
HeaderVal = cowboy_req:header(<<"content-type">>, Req, <<"text/plain">>).
All headers can be retrieved at once, either directly:
#{headers := AllHeaders} = Req.
Or using a function:
To parse a specific header:
To retrieve the peer directly:
#{peer := {IP, Port}} = Req.
And using a function: