Skip to content

Instantly share code, notes, and snippets.

@hornbeck
Created October 29, 2008 13:14
Show Gist options
  • Save hornbeck/20689 to your computer and use it in GitHub Desktop.
Save hornbeck/20689 to your computer and use it in GitHub Desktop.
handle("/todo/new", Req) ->
Params = Req:parse_post(),
Status = proplists:get_value("status", Params),
Description = proplists:get_value("description", Params),
todo:add_todo(Status, Description),
redirect_to(Req, "/");
handle("/json", Req) ->
Todos = todo:get_todos(),
ParsedTodos = [{X#todo.status, X#todo.description} || X <- Todos ],
Json = list_to_binary(mochijson2:encode({struct, ParsedTodos })),
Req:respond({200, [{"Content-Type", "text/javascript"}], Json});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment