nova_basic_handler (NOVA vv0.8.0)
Link to this section Summary
Functions
Handler for JSON. It takes two different return objects
Handler for regular views. This will render a template with given variables. If not another view is specified in options a view that corresponds to the controller will be rendered.
Handler for returning http status codes. There's three different ways one can return status code. The most basic case is {status, Status} where Status is the code that should be returned.
Link to this section Types
erlydtl_vars/0
Specs
erlydtl_vars() :: map() | [{Key :: atom() | binary() | string(), Value :: any()}].
mod_fun/0
Specs
mod_fun() :: {Module :: atom(), Function :: atom()} | undefined.
Link to this section Functions
handle_json(_, ModFun, State)
Specs
handle_json({json, JSON :: map()} |
{json, StatusCode :: integer(), Headers :: map(), JSON :: map()},
ModFun :: mod_fun(),
State) ->
{ok, State} | {Module :: atom(), State}
when State :: nova:state().
Handler for JSON. It takes two different return objects:
returns the JSON encoded to the user. If the operation was a POST the HTTP-status code will be 201, otherwise 200. Same operation as the above except you can set custom status code and custom headers.handle_ok(_, ModFun, State)
Specs
handle_ok({ok, Variables :: erlydtl_vars()} | {ok, Variables :: erlydtl_vars(), Options :: map()},
ModFun :: mod_fun(),
State) ->
{ok, State}
when State :: nova:state().
Handler for regular views. This will render a template with given variables. If not another view is specified in options a view that corresponds to the controller will be rendered.
-module(my_first_controller). -compile(export_all). my_function(_Req) -> {ok, []}. The example above will then render the view named 'app_main.dtl'
Options can be specified as follows:
- view - Specifies if another view should be rendered instead of default one
- headers - Custom headershandle_redirect(_, ModFun, State)
Specs
handle_redirect({redirect, Route :: list()}, ModFun :: mod_fun(), State) -> {ok, State}
when State :: nova:state().
handle_sendfile(_, ModFun, State)
Specs
handle_sendfile({sendfile,
StatusCode :: integer(),
Headers :: map(),
{Offset :: integer(), Length :: integer(), Path :: list()},
Mime :: binary()},
ModFun :: mod_fun(),
State) ->
{ok, State}
when State :: nova:state().
handle_status(_, ModFun, State)
Specs
handle_status({status, StatusCode :: integer()} |
{status, StatusCode :: integer(), ExtraHeaders :: map()} |
{status, StatusCode :: integer(), ExtraHeaders :: map(), Body :: binary() | map()},
ModFun :: mod_fun(),
State) ->
{ok, State}
when State :: nova:state().
Handler for returning http status codes. There's three different ways one can return status code. The most basic case is {status, Status} where Status is the code that should be returned.
If there's a need for additional headers to be sent along with the http code one can specify a third argument that is a map with header-fields.
One can also send in a body as a fourth argument in the tuple. It can either be a binary or a map. If it's a map it will be concidered a JSON-structure and encoded.handle_websocket(_, ModFun, State)
Specs
handle_websocket({websocket, ControllerData :: any()}, ModFun :: mod_fun(), State :: nova:state()) ->
{ok, State :: nova:state()}.