Created
February 24, 2014 03:39
-
-
Save beezee/9181592 to your computer and use it in GitHub Desktop.
Chicago Boss universal RESTFUL json resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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