How can I process a POST submission in Webmachine?

1.4k views Asked by At

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

1

There are 1 answers

2
Roberto Aloi On

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