leptus_req module
Table of Contents
leptus_req module
Please keep it in mind that Req is a Pid that should be used as the first
argument in leptus_req functions.
All the functions given below are accessible through the leptus_req module,
which are supposed to work with the Req object.
Functions
param/2
Returns a parameter that is bound to the route.
param(Req, Name :: atom()) -> binary() | undefined %% e.g. %% route: /items/:id %% requested uri: /items/1863 param(Req, id) -> <<"1863">>
params/1
Returns parameters that are bound to the route.
params(Req) -> [{atom(), binary()}]
%% e.g.
params(Req) -> [{id, <<"1863">>}]
qs/1
Returns query strings.
qs(Req) -> binary() %% e.g. %% uri: /items/?limit=50 qs(Req) -> <<"limit=50">>
qs_val/2
Returns the given query string value.
qs_val(Req, Field :: binary()) -> binary() | undefined %% e.g. qs_val(Req, <<"limit">>) -> <<"50">>
version/1
Returns HTTP version.
version(Req) -> 'HTTP/1.1' | 'HTTP/1.0' %% e.g. version(Req) -> 'HTTP/1.1'
body/1
Returns received body (decoding might apply to it).
body(Req) -> binary() | json_term()
%% e.g.
body(Req) -> <<"foo=bar">>
%% when content-type is set to applicaation/json or application/msgpack
body(Req) -> [{<<"function">>, <<"body/1">>}]
body_raw/1
Returns raw body.
body_raw(Req) -> binary()
%% e.g.
body_raw(Req) -> <<"{\"function\": \"body/1\"}">>
body_qs/1
Returns body but in query string format.
body_qs(Req) -> [{binary(), binary() | true}]
%% e.g.
body_qs(Req) -> [{<<"foo">>, <<"bar">>}]
header/2
Returns the given header value.
header(Req, binary()) -> binary() | undefined %% e.g. header(Req, <<"content-type">>) -> <<"application/x-www-form-urlencoded">>
header/3
Returns the given header value or the default value if the header does not exist.
header(Req, binary(), Default) -> binary() | Default %% e.g. header(Req, <<"content-type">>, undefined) -> undefined
parse_header/2
Parses the given header.
parse_header(Req, binary()) -> any() | undefined | {error, any()}
%% e.g.
parse_header(Req, <<"content-type">>) -> {<<"application">>, <<"json">>, []}
auth/2
Checks for the given authorization method.
NOTE: basic authentication is only supported at the moment.
auth(Req, basic) -> {binary(), binary()} | <<>> | error
%% e.g.
auth(Req, basic) -> {<<"username">>, <<"p4ssw0rd">>}