A
A
Alexander2014-11-24 23:40:34
Erlang
Alexander, 2014-11-24 23:40:34

Erlang how to get the current url?

Tell the learner of erlang how to get the current url and get its get parameters.
The purpose of requests:
/route/{ID} or /route/?id={ID}
to get an ID and act according to the situation.
I use otp 17, cowboy, ratchet.
Failed to google answer

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-11-26
@SpaceMaster1

Cowboy_req:path + functions from the re module will probably help you in the case of CNC.
and as far as I remember cowboy_req:qs + cow:parse_qs in the case of id as a GET parameter.
Links for studying the source:
https://github.com/ninenines/cowboy/blob/master/sr...
https://github.com/ninenines/cowlib/blob/master/sr...
And also the manual: ninenines .eu/docs/en/cowboy/HEAD/manual

D
Dmitry Tyuterev, 2015-01-30
@dmitryttt

You need cowboy_req:binding
Dispatch = cowboy_router:compile([
{'_', [
{"/:service/:controller/:action/[:id/[...]]", kf_route_handler, []}
]}
] ),
handle(Req, State) ->
lager:info("~p",[Req]),
{Controller, _} = cowboy_req:binding(controller, Req, <<"index">>),
{Action, _} = cowboy_req:binding(action, Req, <<"index">>),
{M, _} = cowboy_req:method(Req),
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question