[erlang-questions] problems with cowboy hello world

Kenneth Lakin kennethlakin@REDACTED
Thu Mar 12 06:07:56 CET 2015

On 03/11/2015 09:18 PM, Garry Hodgson wrote:
> i'm trying to port a webmachine application to cowboy,
> with puzzling results so far. i've got all the plumbing set
> up, and my handlers get called. i actually need to use
> cowboy_rest_handler, but am trying first to get basic http
> working. so i copied the example from the User Guide:

If you're using Cowboy 1.0.x, (as I am), then I learned that you can't
actually make a response in init/3. (I got exactly the same stacktrace
that you're reporting.) All work has to be done in handle/2.

This *should* be a correct Cowboy 1.0.x Hello World:

-module( hello_api ).
-export([ init/3, handle/2, terminate/3 ]).

handle(Req, State) ->
  {ok, Req2} = cowboy_req:reply(200, [
                                {<<"content-type">>, <<"text/plain">>}
                               ], <<"Hello World!">>, Req),
  {ok, Req2, State}.

init(_Type, Req, _Opts) ->
  {ok, Req, no_state}.

terminate(_Reason, _Req, _State) ->

I can't speak to how you would do this with with Cowboy HEAD.

(As an aside, I very much dislike how erlang.mk treats all warnings as
errors. I'm much more pleased when using rebar as a build system.)

More information about the erlang-questions mailing list