How can I process a POST request in Webmachine?

Can any soul show me how to write or tell me a simple Webmachine request to handle a POST request; for example something like:

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

Thank you very much,

Lrp

+4
source share
1 answer

Given your webmachine resource, you guarantee 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 process your PUT request in 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 is another example of how to manage a simple POST request:

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

+4
source

Source: https://habr.com/ru/post/1382400/


All Articles