Direct code, everything is not in the words
Percent of cowboy restful documents, be sure to read HTTP well://ninenines.eu/docs/en/cowboy/head/manual/cowboy_rest/Percent of a few large post-submission methods https://imququ.com/post/four-ways-to-post-data-in-http.htmlPercent Curl Test command curl-l-H"Content-type:application/json"-X POST http://127.0.0.1:8080-d "AAA=BBB"-module (restful_handler).-export ([init/2]).-export ([allowed_methods/2]).-export ([content_types_provided/2]).-export ([content_types_accepted/2]).-export ([delete_completed/2]).-export ([delete_resource/2]).-export ([hello_to_html/2]).-export ([form_urlencoded_post/2]).-export ([form_data_post/2]).-export ([json_post/2]). Init (Req, Opts)-{cowboy_rest, Req, Opts}.allowed_methods (Req, State)-Methods= [ <<"HEAD">>, <<"GET">>, <<"POST">>, <<"PATCH">>, <<"DELETE">>, <<"OPTIONS">>], {Methods, Req, state}.content_types_provided (Req, State)-handlers= [ {<<"text/html">>, hello_to_html}, {<<"application/x-www-form-urlencoded">>, Form_urlencoded_post}, {<<"Multipart/form-data">>, Form_data_post}, {<<"Application/json">>, Json_post}], {handlers, Req, state}.content_types_accepted (Req, State)-handlers= [ {<<"application/x-www-form-urlencoded">>, Form_urlencoded_post}, {<<"Multipart/form-data">>, Form_data_post}, {<<"Application/json">>, Json_post}], {handlers, Req, state}.delete_completed (Req, State)-Io:format ("Would delete resource~n"), {true, Req, State}.delete_resource (Req, State)-Io:format ("Delete Resource Finish~n"), {true, Req, state}.hello_to_html (Req, State)-Body= <<"HTML">>, {Body, Req, State}.form_urlencoded_post (Req, State)-{OK, postvals, _req2}=Cowboy_req:body_qs (req), PostVal1= Proplists:get_value (<<"AAA">>, Postvals), PostVal2= Proplists:get_value (<<"BBB">>, Postvals), Io:format ("Form_urlencoded_post~p~p~n", [Postval1,postval2]), Body=string: Concat (Erlang:bitstring_to_list (POSTVAL1), Erlang:bitstring_to_list (PostVal2)), Newreq=Cowboy_req:set_resp_body (erlang:list_to_bitstring (body), req), {true, Newreq, State}.form_data_post (Req, State)-{OK, postvals, _req2}=Cowboy_req:body_qs (req), Postval= Proplists:get_value (<<"AAA">>, Postvals), Io:format ("Form_data_post~p~n", [Postval]), Newreq=Cowboy_req:set_resp_body (postval,req), {true, Newreq, State}.json_post (Req, State)-{OK, postvals, _req2}=Cowboy_req:body_qs (req), Postval= Proplists:get_value (<<"AAA">>, Postvals), Io:format ("Json_post~p~n", [Postval]), Newreq=Cowboy_req:set_resp_body (postval,req), {true, Newreq, state}.
Examples of cowboy using restful