2

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.

Gokul
  • 455
  • 6
  • 17

1 Answers1

4

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.

Muzaaya Joshua
  • 7,736
  • 3
  • 47
  • 86
  • this code must reside in the page which is receiving the `action` from the form OR the page `exile.yaws`. If the page is an `appmod`, ensure that you have included the two yaws include files i.e. `yaws_api.hrl` and `yaws.hrl` in your module `exile.erl` before compilation, and then added as `appmods = ` under the concerned server in the yaws.conf file. Just read about `appmods` from the documentation on the yaws home page. – Muzaaya Joshua Jan 04 '12 at 06:39