Created
January 8, 2014 17:57
-
-
Save hamidreza-s/8321228 to your computer and use it in GitHub Desktop.
Just a proposal for Lebtus framework to add use middleware.
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
-module(rq_handler). | |
-compile({parse_transform, leptus_pt}). | |
%% leptus callbacks | |
-export([init/3]). | |
-export([get/3]). | |
-export([use/3]). | |
-export([terminate/3]). | |
init(_Route, _Req, State) -> | |
{ok, State}. | |
%% general middlewares | |
use(Route, Req, State) -> | |
%% logger middleware | |
Logger = spawn(loggerModule, handlerFunction, []), | |
Logger ! {self(), Route, Req, State}, | |
%% site counter middleware | |
Counter = spawn(counterModule, handlerFunction, []), | |
Counter ! {self(), Route, Req, State}, | |
%% etc ... | |
ok. | |
get("/", _Req, State) -> | |
{<<"Hello, leptus!">>, State}; | |
get("/hi/:name", Req, State) -> | |
Status = 200, | |
Name = leptus_req:param(name, Req), | |
Body = [{<<"say">>, <<"Hi">>}, {<<"to">>, Name}], | |
{Status, {json, Body}, State}. | |
terminate(_Reason, _Req, _State) -> | |
ok. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment