Skip to content

Instantly share code, notes, and snippets.

@beezee
Created February 24, 2014 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beezee/9181592 to your computer and use it in GitHub Desktop.
Save beezee/9181592 to your computer and use it in GitHub Desktop.
Chicago Boss universal RESTFUL json resource
-module(app_name_domain_controller, [Req]).
-compile(export_all).
all('GET', [Type]) ->
% TODO: expand flexibility of filtering interface
{json, boss_db:find(list_to_atom(Type), lists:map(fun({K, V}) -> {list_to_atom(K), 'equals', V} end,
Req:query_params()), [{order_by, last_update}, {order, desc}])}.
show('GET', [Id]) ->
Model = boss_db:find(Id),
case Model of
undefined ->
{json, [{error, "Record not found"}]};
_Else ->
{json, Model}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment