At [[http://2600hz.org][2600Hz]], we recently converted our REST
webserver from
[[https://github.com/mochi/mochiweb][Mochiweb]]/[[https://github.com/basho/webmachine][Webmachine]]
to [[https://github.com/extend/cowboy][Cowboy]], with
[[https://github.com/extend/cowboy/blob/master/src/cowboy_http_rest.erl][cowboy\_http\_rest]]
giving us a comparable API to process our REST requests with. One
feature that was missing, however, was an equivalent to Webmachine's
[[http://wiki.basho.com/Webmachine-Resource.html#Halting-Resources][{halt,
StatusCode}]] return. While there has been
[[https://github.com/extend/cowboy/pull/144][chatter]] about adding this
to cowboy\_http\_rest, we've got a function that emulates the behaviour
pretty well (this is cleaned up a bit from our actual function, removing
project-specific details).

#+BEGIN_EXAMPLE
    -spec halt/4 :: (#http_req{}, integer(), iolist(), #state{}) -> {'halt', #http_req{}, #state{}}.
    halt(Req0, StatusCode, RespContent, State) ->
        {ok, Req1} = cowboy_http_req:set_resp_body(Content, Req0),
        {ok, Req2} = cowboy_http_req:reply(StatusCode, Req1),
        {halt, Req2, State}.
#+END_EXAMPLE

Obviously you can omit setting the response body if you don't plan to
return one.
