XUtils

Giallo

A small and flexible web framework on top of [Cowboy](https://github.com/ninenines/cowboy).


{redirect, Location}

Redirect to the Location effectively bypassing the Action

Return values

Here’s a list of possible return values from a Giallo controller.

All return values can take an optional Req :: cowboy_req:req() as the last parameter. This is especially useful if you need to set anything special to the response, like cookies, sessions, etc.

ok

Continue and render the template for the corresponding action

{ok, Variables::proplist()}

Same as above but pass Variables to the template. Variables can then be outputted in the template as {{ variable_name }}

{ok, Variables::proplist(), Headers::proplist()}

Same as above but also set additional HTTP Headers

{redirect, Location::binary()

Send a 302 redirect to the Location

{redirect, Location::binary(), Headers::proplist()}

Same as above but also set additional HTTP Headers

{moved, Location::binary()}

Send a 301 redirect to the Location

{moved, Location::binary(), Headers::proplist()}

Same as above but also set additional HTTP Headers

{action_other, Location::proplist()}

Possible values for Location are [{action, your_action}, {controller, your_handler}]. If controller is ommitted it will assume the current handler.

{action_other, Location::proplist(), Variables::proplist()}

Same as above but pass Variables that can be retrieved from the controller.

{render_other, Location::proplist()}

Render the view associated with the Action at Location. Possible values for Location are [{action, your_action}, {controller, your_handler}]. If controller is ommitted it will assume the current handler.

{render_other, Location::proplist(), Variables::proplist()}

Same as above but pass Variables that can be retrieved in the template. Possible values for Location are [{action, your_action}, {controller, your_handler}]. If controller is ommitted it will assume the current handler.

{output, Output::binary()}

print out the Output

{output, Output::binary(), Headers::proplist()}

Same as above but also set additional HTTP Headers

{stream, Generator::function(), Acc0::any()}

Stream a response to the client using HTTP chunked encoding. For each chunk, the Generator function is passed an accumulator (initally Acc0) and should return either {output, Data, Acc1} or done. I.e:


stream(<<"GET">>, _Pathinfo, _Extra, _Req) ->
    F = fun(Acc) ->
            case Acc =:= 3 of
                true  -> done;
                false -> {output, <<"Hello\n">>, Acc+1}
            end
    end,
    {stream, F, 0}.

{stream, Generator::function(), Acc::any(), Headers::proplist()}

Same as above but also set additional HTTP Headers

{json, Data::proplist()}

Encode the Data as json and output

{json, Data::proplist(), Headers::proplist()}

Same as above but also set additional HTTP Headers

{jsonp, Callback::string(), Data::proplist()}

Encode the Data as valid jsonp using the Callback

{jsonp, Callback::string(), Data::proplist(), Headers::proplist()}

Same as above but also set additional HTTP Headers

not_found

Respond with a 404

{error, Status::integer()}

Respond with the given error Status Code

Request processing

There is some conventience-functions for working with headers, querystrings, multipart-data, etc. Please generate and look at the docs:


make doc


Articles

  • coming soon...