How do i get values from this URL? and execute an erlang module with the values to reply the client with result?

StackOverflow https://stackoverflow.com/questions/8720656

  •  13-04-2021
  •  | 
  •  

Question

http://www.myserver.com/exile?Key1=Value1&Key2=Value2

When i get a request in this format to my server, how do i handle this request? What i need to do: Need to get all the values and run a Erlang module, and send the result to the client.Is exile a CGI and if so how come it doesn't have a .cgi extension?

Additional Data: I have setup an Yaws on my server(Desktop running linux server). yaws.conf file is configured.

Was it helpful?

Solution

Here are the solutions:

<erl>

out(A)->
    Values = yaws_api:parse_query(A),
    Value1 = proplists:get_value("Key1",Values),
    Value2 = proplists:get_value("Key2",Values),
    %% then do anything with them ....
    %% ....
    {html,"Json Data or HTML tags or XML data or string of data"}.
    %% or {ehtml,[{p,[],""}]}.

<erl>

More information here: http://yaws.hyber.org/query.yaws

OR

<erl>

out(A)->
    Value1 = yaws_api:queryvar(A,"Key1"),
    Value2 = yaws_api:queryvar(A,"Key2"),
    %% Need to be careful here
    %% if the value aint found, the 
    %% variable will contain an atom 'undefined'
    %% then do anything with them ....
    %% ....
    {html,"Json Data or HTML tags or XML data or string of data"}.
    %% or {ehtml,[{p,[],""}]}.

<erl>

OR

<erl>

out(A)->
    Value1 = yaws_api:getvar(A,"Key1"),
    Value2 = yaws_api:getvar(A,"Key2"),
    %% Need to be careful here
    %% if the value aint found, the 
    %% variable will contain an atom 'undefined'
    %% then do anything with them ....
    %% ....
    {html,"Json Data or HTML tags or XML data or string of data"}.
    %% or {ehtml,[{p,[],""}]}.

<erl>

Read more on Module: yaws_api.erl

*NOTE * avoid using the last option (getvar/2) because it first checks the POST data and then also checks the GET data, looking for your specified parameter. It should only be used when you are not sure wether the parameter is coming along the GET or POST request data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top