Skip to content

Instantly share code, notes, and snippets.

@l4u
Created May 3, 2012 04:07
Show Gist options
  • Save l4u/2583070 to your computer and use it in GitHub Desktop.
Save l4u/2583070 to your computer and use it in GitHub Desktop.
Chicagoboss tutorial output json
-module(cb_tutorial_greeting_controller, [Req]).
-compile(export_all).
hello('GET', []) ->
{json, [{greeting, "Hello, world!"}]}.
list('GET', []) ->
Greetings = boss_db:find(greeting, []),
case Greetings of
[] ->
{output, <<"[]">>, [{"Content-Type", "application/json"}]};
_Else ->
Greetings1 = [{greeting:id(G), greeting:greeting_text(G)}
|| G <- Greetings],
{json, [{greetings, Greetings1}]}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment