{"id":2449,"date":"2022-08-30T15:24:57","date_gmt":"2022-08-30T15:24:57","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/12\/how-to-set-status-code-in-rest-post-in-cowboy-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:57","modified_gmt":"2022-08-30T15:24:57","slug":"how-to-set-status-code-in-rest-post-in-cowboy-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-set-status-code-in-rest-post-in-cowboy-collection-of-common-programming-errors\/","title":{"rendered":"How to set status code in REST POST in cowboy-Collection of common programming errors"},"content":{"rendered":"<p>How can I set status code in my REST POST resource.<\/p>\n<p>Now I&#8217;m doing this<\/p>\n<pre><code>make_post(Req, State) -&gt;\n  lager:info(\"post\"),\n  Resp = cowboy_req:set_resp_body(, Req),\n  {ok, Resp3} = cowboy_req:reply(201, Resp),\n  {true, Resp3, State}.\n<\/code><\/pre>\n<p>But I receive such errors:<\/p>\n<p>1:43:10.510 [info] [nonode@nohost#pbshare_logic_registration#] [handle_info#35] :Exit Logic from Reason: {function_clause,[{cowboy_req,reply,[204,[],,{http_req,#Port,ranch_tcp,keepalive,,,&#8217;HTTP\/1.1&#8242;,{{127,0,0,1},50024},,undefined,8080,,[],,undefined,[],[{,},{,},{,&gt;},{,},{,}],[{,14},{,undefined},{,14},{,{,,[]}},{,undefined},{,undefined},{,undefined},{,undefined},{,[{{&gt;,&gt;,[]},1000,[]}]}],undefined,[{charset,undefined},{media_type,{,,[]}}],done,undefined,,false,done,[],,undefined}],[{file,&#8221;src\/cowboy_req.erl&#8221;},{line,948}]},{cowboy_rest,respond,3,[{file,&#8221;src\/cowboy_rest.erl&#8221;},{line,1085}]},{cowboy_rest,upgrade,4,[{file,&#8221;src\/cowboy_rest.erl&#8221;},{line,75}]},{cowboy_protocol,execute,4,[{file,&#8221;src\/cowboy_protocol.erl&#8221;},{line,523}]}]} 21:43:10.510 [error] [Undefined#Undefined#emulator] [Undefined#Undefined] :Error in process with exit value: {function_clause,[{cowboy_req,reply,[204,[],,{http_req,#Port,ranch_tcp,keepalive,,,&#8217;HTTP\/1.1&#8242;,{{127,0,0,1},50024},,undefined,8080,,[],,undefined,[],[{,},{,},{,},{,},{,}],[{,14},{,undefined},{,14},{,{,,[]}},{,undefined},{,undefined},{,undefined},{,undefined&#8230;<\/p>\n<p>It seems that cowboy tries to send response once again after my reply. But I didn&#8217;t any other method in API which can change status code.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-12 20:50:49. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>How can I set status code in my REST POST resource. Now I&#8217;m doing this make_post(Req, State) -&gt; lager:info(&#8220;post&#8221;), Resp = cowboy_req:set_resp_body(, Req), {ok, Resp3} = cowboy_req:reply(201, Resp), {true, Resp3, State}. But I receive such errors: 1:43:10.510 [info] [nonode@nohost#pbshare_logic_registration#] [handle_info#35] :Exit Logic from Reason: {function_clause,[{cowboy_req,reply,[204,[],,{http_req,#Port,ranch_tcp,keepalive,,,&#8217;HTTP\/1.1&#8242;,{{127,0,0,1},50024},,undefined,8080,,[],,undefined,[],[{,},{,},{,&gt;},{,},{,}],[{,14},{,undefined},{,14},{,{,,[]}},{,undefined},{,undefined},{,undefined},{,undefined},{,[{{&gt;,&gt;,[]},1000,[]}]}],undefined,[{charset,undefined},{media_type,{,,[]}}],done,undefined,,false,done,[],,undefined}],[{file,&#8221;src\/cowboy_req.erl&#8221;},{line,948}]},{cowboy_rest,respond,3,[{file,&#8221;src\/cowboy_rest.erl&#8221;},{line,1085}]},{cowboy_rest,upgrade,4,[{file,&#8221;src\/cowboy_rest.erl&#8221;},{line,75}]},{cowboy_protocol,execute,4,[{file,&#8221;src\/cowboy_protocol.erl&#8221;},{line,523}]}]} 21:43:10.510 [error] [Undefined#Undefined#emulator] [Undefined#Undefined] :Error in process with exit value: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2449","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2449"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2449\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}