The Chicago Boss API is mostly stable, but still might change before 1.0.
Jump to: Return values SimpleBridge request object
Chicago Boss associates each URL with a function of a controller.
The URL foo_controller:bar.
Each controller module should go into your project's Web/ directory and the file name should end with "_controller.erl".
Helper functions should go in modules that end in "_lib.erl".
Controllers should take one parameter, the SimpleBridge request object. Declare it like:
Each exported controller function takes two or three arguments:
- First argument: the HTTP request method as an atom, e.g.
'GET'or'POST' - Second argument: the list of slash-separated tokens after the action name in the URL.
- Third argument (optional): the result of a function named
'_auth'in the controller
Example function clauses:
view('GET', []) ->
...
% GET /blog/view/1234
view('GET', [Id]) ->
...
% GET /blog/view/tag/funny
view('GET', ["tag", Tag]) ->
...
% GET /blog/view/tag/funny/author/saint-paul
view('GET', ["tag", Tag, "author", AuthorName]) ->
...
% GET /blog/view/2009/08
view('GET', [Year, Month]) ->
...
If an action takes three arguments, then the function '_auth'/1 in your controller will be passed the action name as an atom and should return one of:
ExtraInfo will be passed as the third argument to the action.
Do not execute the action. Instead, perform a 302 redirect to Location.
Probably most common _auth looks like:
my_user_lib:require_login(Req).
Which might return a tuple of user credential or else redirect to a login page. This way, if you want to require a login to a set of actions, just give those actions a User argument, and the actions will be login protected and have access to the User variable.
Whether or not it takes a third argument, a controller action should return with one of the following:
The template will be rendered without any variables.
Variables will be passed into the associated Django template.
Variables will be passed into the associated Django template, and Headers are HTTP headers you want to set (e.g., Content-Type).
Perform a 302 HTTP redirect to Location.
Perform a 302 HTTP redirect to Location and set additional HTTP Headers.
OtherLocation = {Controller::atom(), Action::atom()}
Execute the specified controller action, but without performing an HTTP redirect.
OtherLocation = {Controller::atom(), Action::atom()}
Render the view from OtherLocation, but don't actually execute the associated controller action.
OtherLocation = {Controller::atom(), Action::atom()}
Render the view from OtherLocation using Variables, but don't actually execute the associated controller action.
Skip views altogether and return Output to the client.
Skip views altogether and return Output to the client while setting additional HTTP Headers.
Controller functions are passed a SimpleBridge request object (slightly modified for Boss's purposes). Useful functions in the request object include:
Get the request method, e.g. GET, POST, etc.
Get the value of a given query string parameter (e.g. "?id=1234")
Get the value of a given POST parameter
Get the value of a given HTTP request header
Get the value of a given cookie.