Created
December 7, 2011 22:52
-
-
Save teburd/1445137 to your computer and use it in GitHub Desktop.
cowboy rest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @author Tom Burdick <[email protected]> | |
%% @copyright 2011 Tom Burdick | |
%% @doc Nyuro Web Default Handler. | |
-module(nyuro_web_default). | |
%% cowboy_http_handler api | |
-export([init/3, rest_init/2, content_types_provided/2, to_html/2]). | |
init({_Any, http}, _Req, []) -> | |
{upgrade, protocol, cowboy_http_rest}. | |
rest_init(Req, _Opts) -> | |
error_logger:info_msg("default rest init~n"), | |
{ok, Req, []}. | |
content_types_provided(Req, State) -> | |
error_logger:info_msg("default rest content types~n"), | |
{[{<<"text/html">>, to_html}], Req, State}. | |
to_html(Req, State) -> | |
error_logger:info_msg("default rest to html~n"), | |
{Session, Headers, Req2} = nyuro_session:start([], Req), | |
Attrs = nyuro_session:user_attrs(Session), | |
{ok, Body} = default_dtl:render(Attrs), | |
{ok, Req3} = cowboy_http_req:reply(200, Headers, Body, Req2), | |
{ok, Req3, State}. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment