4

Can some kind soul show me how to write, or point me to, a SIMPLE Webmachine request to process a POST request; e.g. submitted by something like:

<form name="input" action="yada yada" method="post">
   Username: <input type="text" name="fname" />
   <input type="submit" value="Submit" />
</form>   

Many thanks,

LRP

Lloyd R. Prentice
  • 4,329
  • 3
  • 21
  • 31

1 Answers1

4

Given your webmachine resource, you ensure that the 'POST' atom is contained in the list of allowed methods:

allowed_methods(ReqData, Context) ->
    {['HEAD', 'GET', 'PUT', 'DELETE', 'POST'], ReqData, Context}.

Then you can handle your PUT request into the following function:

process_post(ReqData, Context) ->
...
{true, Context}.

A tutorial for this is available at:

http://www.planeterlang.org/en/planet/article/The_BeeBole_ErlangWeb_Tutorial_Webmachine-Style/

Here's another example on how to manage a simple POST request:

https://bitbucket.org/bryan/wmexamples/src/tip/src/formjson_resource.erl

Roberto Aloi
  • 30,570
  • 21
  • 75
  • 112
  • Ah, I spoke too soon. There's stuff I still don't understand here. The json references in the tutorials only confuse me. Suppose, to take it one step at a time, I just want to echo back the values submitted in the example form shown in my question. How do I pull the values out of the request body echo them back via, say io:format/2? – Lloyd R. Prentice Nov 23 '11 at 06:10
  • Hm. The examples show how to process a query string and how to produce a respons, but they don't show how to access the http POST request payload – Pum Walters Oct 10 '14 at 10:36